1

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

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)

有什么可以帮忙的吗?

4

1 回答 1

3

进程替换不是 POSIX sh ( #!/bin/sh,也可以用 ) 调用的可用功能sh yourscript;尽管将此问题标记为“bash”,但您显然是在使用非 bash shell 执行脚本(或者正在进入可移植模式,如set -o posix)。

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

于 2016-02-15T21:46:17.110 回答