设想:
$ process(){ echo "[$1] [$2] [$3]" ; } ; export -f process
$ process "x" "" "a.txt"
[x] [] [a.txt]
在这里我们看到第二个参数是空字符串(预期)。
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" ""
[x] [./a.txt] []
[x] [./b.txt] []
[x] [./c.txt] []
在这里我们看到第二个参数是 find 的输出(意外)。
预期输出:
[x] [] [./a.txt]
[x] [] [./b.txt]
[x] [] [./c.txt]
怎么修?
""
注意:如果第二个参数从to更改"y"
,则 find 的输出将作为第三个参数出现(预期):
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" "y"
[x] [y] [./a.txt]
[x] [y] [./b.txt]
[x] [y] [./c.txt]
为什么find 的输出不""
作为第三个参数出现?
UPD:看来解决方案是\"\"
:
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" \"\"
[x] [] [./a.txt]
[x] [] [./b.txt]
[x] [] [./c.txt]
但是,我不确定这是否是正确的通用解决方案。这是反例:
$ VAR="" ; find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" "$VAR"
[x] [./a.txt] []
[x] [./b.txt] []
[x] [./c.txt] []