Running bash script using gnu parallel Running bash script using gnu parallel bash bash

Running bash script using gnu parallel


parallel doesn't send the lines of input to stdin of the command given to it, but appends the line to the command you give.

If you write it like you have, then you're effectively calling ./myscript.sh <INPUT>, where you want to call ./myscript.sh, and send the input as stdin.

This should work:

head -n5 file1 | parallel -j 4 "echo {} | ./myscript.sh"

The {} indicates to parallel where you want the input to go, rather than the default of at the end.


--pipe is made for you:

cat file1 | parallel --pipe -N5 ./myscript.sh

But you need to change myscript.sh so it does not save to result but instead print the output to stdout. Then you can:

cat file1 | parallel --pipe -N5 ./myscript.sh > result

and avoid any mixing.