为什么这个 bash 脚本启动 vlc 两次?

Why does this bash script launch vlc twice?

这是我使用动态播放列表启动 vlc 的脚本

#!/bin/bash

find "/path/to/music" -type f -path "**" -print0 | xargs -0 vlc

当 运行 不带参数时,vlc 启动并播放目录树中的文件。

然后我关闭 vlc,另一个实例启动。

如果我将每个实例中的播放列表与

的输出进行比较
find "/path/to/music" -type f -path "**"

事实证明,第一个实例获得了大部分播放列表,第二个实例获得了其余部分。拆分是确定性的。以下是上述命令输出的摘录:

...
/path/to/music/Liz Carroll/Lost in the Loop/08 - The Crow in the Sun.ogg
/path/to/music/Liz Carroll/Lost in the Loop/02 - The Champaign Jig Goes To Columbia, Pat and Al's.ogg
/path/to/music/Liz Carroll/Lost in the Loop/04 - The Golden Legs, The Flogging Reel.ogg
/path/to/music/Liz Carroll/Lost in the Loop/09 - The Ugly Duckling.ogg
/path/to/music/Liz Carroll/Lost in the Loop/03 - See It There, Con Cassidy's.ogg
/path/to/music/Liz Carroll/Lost in the Loop/13 - The Didda, Fly and Dodger.ogg
/path/to/music/Eliza Carthy/Dreams of Breathing Underwater/08 Little Bigman.mp3
/path/to/music/Eliza Carthy/Dreams of Breathing Underwater/07 Lavenders.mp3
...

分割总是发生在第二个实例的播放列表中最后三个文件是第一个。那里似乎没有任何技巧角色。包含撇号的文件名按应有的方式出现在 vlc 播放列表中,似乎没有丢失任何内容,并且 vlc 输出没有错误。

为什么vlc的第一个实例没有得到find输出中的所有文件?

为什么有第二个实例得到剩下的?

您可以作为命令行参数传递的字符数有上限。这就是 xargs 的用途:将输入拆分为多个块,如果它们的组合大小太大,则将它们传递给单独的程序调用。

正如man xargs所说:

The command line for command is built up until it reaches a system-defined limit (unless the -n and -L options are used). The specified command will be invoked as many times as necessary to use up the list of input items. In general, there will be many fewer invocations of command than there were items in the input.

在您的例子中,在两次 vlc 调用中处理了数千个输入项。