"syntax error near expected token" using process substition

434 Views Asked by At

It's a bit of embarrassing question but i can not found the error. I am trying to do process substitution. Here is my code

while read compareFile1 <&3 && read compareFile2 <&4; do 
echo compareFile1
echo compareFile2
done 3< <(tail -n+4 test2.txt) 4< <(tail -n+4 test2.txt)

but the error is,

sh.sh: line 7: syntax error near unexpected token `<'
sh.sh: line 7: `done 3< <(tail -n+4 test2.txt) 4< <(tail -n+4 test2.txt)

Any can help?

1

There are 1 best solutions below

3
On BEST ANSWER

Process substitution is not an available feature in POSIX sh (#!/bin/sh, also invoked with sh yourscript); despite tagging this question "bash", you're clearly executing your script with a non-bash shell (or are otherwise entering portability mode, as with set -o posix).

Use bash instead; thus, putting #!/bin/bash at the beginning of your script, or invoking it with bash yourscript if specifying an interpreter manually.