"syntax error near expected token" 使用进程替换

"syntax error near expected token" using process substition

有点尴尬的问题,但我找不到错误。我正在尝试进行流程替换。这是我的代码

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)

但错误是,

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)

有什么可以帮忙的吗?

进程替换不是 POSIX sh 中的可用功能(#!/bin/sh,也用 sh yourscript 调用);尽管标记了这个问题 "bash",你显然正在使用非 bash shell 执行你的脚本(或者以其他方式进入可移植模式,如 set -o posix)。

改用bash;因此,将 #!/bin/bash 放在脚本的开头,或者如果手动指定解释器,则使用 bash yourscript 调用它。