Bash脚本进程替换语法错误:“("意外 [英] Bash script process substitution Syntax error: "(" unexpected

查看:96
本文介绍了Bash脚本进程替换语法错误:“("意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要运行此脚本:

#!/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:

  1. 我使用的shebang是正确的,并选择了bash shell,因此进程替换语法应该可以工作
  2. 我从命令行尝试了同样的方法,并且可以正常工作.我检查了echo $0,它给了我"bash",那么与在命令行中运行命令和调用同一shell的脚本有什么区别?
  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.

推荐答案

在将脚本设置为可执行文件后,应使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆