Bash script process substitution Syntax error: “(” unexpected

白昼怎懂夜的黑 提交于 2019-12-28 02:19:05

问题


I want to run this script:

#!/bin/bash
echo <(true)

I run it as:

sh file.sh

And I get "Syntax error: "(" unexpected" . I found some similar situations but still can't solve this. I'm a beginner at shell scripting , but as I understand:

  1. the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work
  2. I try the same from the command line and it works. I checked with echo $0 and it gives me "bash" , so what's the difference from running the command in the command line and from a script that invokes the same shell?

Maybe it's something simple, but I couldn't find an explanation or solution.


回答1:


You should run your script with bash, i.e. either bash ./script.sh or making use of the shebang by ./script.sh after setting it to executable. Only running it with sh ./script.sh do I get your error, as commented by Cyrus.

See also: role of shebang at unix.SE



来源:https://stackoverflow.com/questions/32038974/bash-script-process-substitution-syntax-error-unexpected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!