Bash脚本进程替换语法错误:“("意外 [英] Bash script process substitution Syntax error: "(" unexpected
问题描述
我要运行此脚本:
#!/bin/bash
echo <(true)
我将其运行为:
sh file.sh
然后我得到"Syntax error: "(" unexpected
".我发现了一些类似的情况,但仍然无法解决.
我是shell脚本的初学者,但据我了解:
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:
- 我使用的shebang是正确的,并选择了bash shell,因此进程替换语法应该可以工作
- 我从命令行尝试了同样的方法,并且可以正常工作.我检查了
echo $0
,它给了我"bash
",那么与在命令行中运行命令和调用同一shell的脚本有什么区别?
- the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work
- 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.
推荐答案
在将脚本设置为可执行文件后,应使用bash
(即bash ./script.sh
或./script.sh
使用shebang)运行脚本.正如Cyrus所说,只有使用sh ./script.sh
运行它,我才能收到您的错误.
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.
另请参见: shebang在unix.SE上的作用
这篇关于Bash脚本进程替换语法错误:“("意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!