使用 xargs 每行一个命令执行一个文件

Executing a file with one command per line with xargs

我有一个包含一系列命令的文件,每行一个。例如:

./run_test_1.sh fileA ./run_test_1.sh fileB ./run_test_2.sh fileC

我想运行这些并行,使用xargs。

试一试:

printf "%s[=10=]" $(cat afile) | xargs -0 -P 3 -I xxx bash -c xxx

xargs 将并行执行来自 afile 的 运行 3 个命令。

命令或其选项中的特殊字符会破坏此解决方案。

----

下面的版本似乎是安全的,但是 afile 中的所有命令都按顺序执行:

printf "%s[=11=]" "$(cat afile)" | xargs -0 -P 3 -I xxx bash -c xxx

-P 3在这里没用