QUESTION
In bash you can pass data from step to step by piping data:
program1 | program2 | program3 | ...
Or you can do this with variables (depending how each program work):
RES1=$(program1)
RES2=$(program2 $RES1)
...
I am looking for counterpart of such passing data in parallel.
EXAMPLE
I try to convert my "linear" script to the amazing parallel (this tool still do wonders for me :-D), but I have a problem with reading and using the output from the first step. Original version:
for fn in $(ls $REV *)
do
DATA=$(sh script1.sh ${fn})
sh script2.sh $DATA
done
Here how I tried to do this with parallel:
ls $REV * | parallel -j+0 DATA=$(sh script1.sh {}) \; sh script2.sh $DATA
However with this code myscript gets some broken data on input. Version with removed reading the result and second step altogether, works:
ls $REV * | parallel -j+0 sh script1.sh {}
So how to read the output from the first step of parallel and use it in next steps?
PROBLEM
For easier debugging let's say my first script (script1.sh) is:
echo "RECEIVED THIS ${1}"
And the main script is:
ls * | parallel -j+0 RES="$(sh script1.sh {})"
(I skipped the script2 here for testing capturing the output of script1). Then the result of entire execution is this:
/bin/bash: THIS: command not found
/bin/bash: THIS: command not found
/bin/bash: THIS: command not found
...