linux - Bash 脚本进程替换语法错误 : "(" unexpected

标签 linux bash shell process-substitution

我想运行这个脚本:

#!/bin/bash
echo <(true)

我将其运行为:

sh file.sh

我得到“Syntax error: "("unexpected"。我发现了一些类似的情况,但仍然无法解决这个问题。 我是 shell 脚本的初学者,但据我了解:

  1. 我使用的 shebang 是正确的并且选择了 bash shell,所以进程替换语法应该可以工作
  2. 我在命令行中尝试了同样的方法,它起作用了。我检查了 echo $0 ,它给了我 "bash",那么在命令行中运行命令和调用相同 shell 的脚本有什么区别?

也许这很简单,但我找不到解释或解决方案。

最佳答案

您应该使用 bash 运行您的脚本,即 bash ./script.sh或使用 ./script.sh 的 shebang将其设置为可执行文件后。仅使用 sh ./script.sh 运行它正如 Cyrus 评论的那样,我是否收到你的错误?

另请参阅:role of shebang at unix.SE

关于linux - Bash 脚本进程替换语法错误 : "(" unexpected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32038974/

相关文章:

linux - Shell,多目录格式不起作用

bash - 使用 groovy,如何通过管道传输多个 shell 命令?

ruby - 无法使用 sudo 启动服务,因为 root 用户无权访问 Ruby

linux - Linux内核中的IS_ALIGNED宏是做什么的?

linux - 如何从源代码正确构建包

linux - Cuda 驱动程序调用返回错误 1 ​​(cudaErrorMissingConfiguration)

java - 如何在 Linux 终端中为 Java 使用 apache commons io?

bash - 相当于 `getrusage()` 的命令行

bash - 将 perl while 循环更改为 shell

linux - 如何在新行上获取 diff 命令的输出