bec*_*cko 9 arrays bash gnu-parallel
如何在GNU中与数组并行提供命令?例如,我有这个数组:
x=(0.1 0.2 0.5)
Run Code Online (Sandbox Code Playgroud)
现在我想把它喂给一些命令 parallel
parallel echo ::: $x
Run Code Online (Sandbox Code Playgroud)
这不起作用.它将所有参数提供给单个调用,因为它打印出来
0.1 0.2 0.5
Run Code Online (Sandbox Code Playgroud)
代替
0.1
0.2
0.5
Run Code Online (Sandbox Code Playgroud)
这是输出
parallel echo ::: 0.1 0.2 0.5
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
Die*_*ano 10
如果要提供数组中的所有元素,请使用:
parallel echo ::: ${x[@]}
Run Code Online (Sandbox Code Playgroud)
来自: http: //www.gnu.org/software/parallel/man.html
示例:使用 shell 变量 使用 shell 变量时,您需要正确引用它们,否则它们可能会被空格分割。
请注意以下之间的区别:
V=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
parallel echo ::: ${V[@]} # This is probably not what you want
Run Code Online (Sandbox Code Playgroud)
和:
V=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
parallel echo ::: "${V[@]}"
Run Code Online (Sandbox Code Playgroud)
当在实际命令中使用包含特殊字符(例如空格)的变量时,您可以使用 '"$VAR"' 或使用 "'s 和 -q 来引用它们:
V="Here are two "
parallel echo "'$V'" ::: spaces
parallel -q echo "$V" ::: spaces
Run Code Online (Sandbox Code Playgroud)