syntax error near unexpected token `<'

前端 未结 2 1212
夕颜
夕颜 2020-12-18 12:35
StudentAnwser=()
inputScriptFile=001.sh

while IFS= read -r line;
do
    StudentAnwser+=( \"$line\" )
done < <( sh $inputScriptFile test.txt )
<
相关标签:
2条回答
  • 2020-12-18 13:07

    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.

    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.

    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:

    Leave #!/bin/bash as it is, make your script an executable by chmod +x foo.sh. Then run it directly by ./foo.sh

    0 讨论(0)
  • 2020-12-18 13:19

    Found another solution: process substitution is not a POSIX-compliant feature and, depending on your system and shell, it might need to be enabled.

    Use the following line in your script, before the loop:

    set +o posix
    

    to enable it. It might be that your system doesn't support it at all, then this is of no help.

    0 讨论(0)
提交回复
热议问题