Scenario:
$ process(){ echo "[$1] [$2] [$3]" ; } ; export -f process
$ process "x" "" "a.txt"
[x] [] [a.txt]
Here we see that the 2nd argument is empty string (expected).
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" ""
[x] [./a.txt] []
[x] [./b.txt] []
[x] [./c.txt] []
Here we see that the 2nd argument is the output of find (unexpected).
Expected output:
[x] [] [./a.txt]
[x] [] [./b.txt]
[x] [] [./c.txt]
How to fix?
Note: if the 2nd argument is changed from ""
to "y"
, then the output of find is present as the 3rd argument (expected):
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" "y"
[x] [y] [./a.txt]
[x] [y] [./b.txt]
[x] [y] [./c.txt]
Why isn't the output of find present as the 3rd argument with ""
?
UPD: It seems that the solution is \"\"
:
$ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" \"\"
[x] [] [./a.txt]
[x] [] [./b.txt]
[x] [] [./c.txt]
However, I'm not sure that this is the correct general solution. Here is the counterexample:
$ VAR="" ; find -name "*.txt" -print | SHELL=$(type -p bash) parallel process "x" "$VAR"
[x] [./a.txt] []
[x] [./b.txt] []
[x] [./c.txt] []
echo x | parallel process "foo bar" ""
, you'll see the output[foo] [bar] [x]
, instead of[foo bar] [x]
– ilkkachu Feb 29 '24 at 10:30