意外令牌'<'附近的语法错误 [英] syntax error near unexpected token `<'
问题描述
StudentAnwser=()
inputScriptFile=001.sh
while IFS= read -r line;
do
StudentAnwser+=( "$line" )
done < <( sh $inputScriptFile test.txt )
返回错误
foo.sh: line 22: syntax error near unexpected token `<'
foo.sh: line 22: ` done < <( sh $inputScriptFile test.txt )'
这有什么问题?我按照其他问题的解决方案从结果中读取行
what's wrong with that? I follow the solution from other question for reading line from result
推荐答案
由于流程替换(<(some command)
部分)不是sh
,这意味着它可以在某些操作系统上运行,但不能在其他操作系统或具有不同配置的同一操作系统上运行.
You get the error because process substitution (the <(some command)
part) is not a standard feature (defined in POSIX) in sh
, which means it may work on some OS but may not in others or in the same OS with different configuration.
您已说明脚本的顶部有#!/bin/bash
,但我想您仍然通过sh foo.sh
运行脚本,因此,#!/bin/bash
将被忽略,脚本由sh
解释.
You clarified that you have #!/bin/bash
at the top of your script, but I guess you still run the script via sh foo.sh
, as such, #!/bin/bash
will be ignored and the script is interpreted by sh
.
我假设您的默认shell是bash
(运行echo $SHELL
),因此如果将脚本粘贴到终端并执行,所有问题都将消失.
I assume your default shell is bash
(run echo $SHELL
), so all problems are gone if you paste the script in terminal and execute.
====更新====
==== UPDATE ====
如果我的假设是正确的,可能的解决方案:
Possible solution if my assumption is correct:
保留#!/bin/bash
的原样,通过chmod +x foo.sh
使您的脚本成为可执行文件.然后直接通过./foo.sh
Leave #!/bin/bash
as it is, make your script an executable by chmod +x foo.sh
. Then run it directly by ./foo.sh
这篇关于意外令牌'<'附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!