【问题标题】:zsh: event not found: /bin/bash -- syntax errorzsh:找不到事件:/bin/bash -- 语法错误
【发布时间】:2023-01-24 15:11:05
【问题描述】:

文件.sh

#!/bin/bash

if { true }
then echo "hi"
fi

我在 shell 脚本中有这个。尝试运行时,我得到:

% ./file.sh
./brackets.sh: line 4: syntax error near unexpected token `then'
./brackets.sh: line 4: `then echo "hi"'

在我的 shell 中运行:

% #!/bin/bash

if { true }
then echo "hi"
fi
zsh: event not found: /bin/bash

在我的 shell 中再次运行:

% if { true }
then echo "hi"
fi
hi

所以问题出在!/bin/bash。有人知道发生了什么事吗?我在网上看了看,但上面的所有帖子都已经过去很久了,而且用户似乎没有在文件/shellscript 中这样做。

我在 MacOS Ventura 上运行 zsh。

【问题讨论】:

  • { true } 并不代表你认为的那样; }true 命令的参数。
  • 输入有效的 shebang 并将您的脚本粘贴到 shellcheck.net 以进行验证/推荐。没有人在做您所做的事情,因为它不是有效的 bash 语法...

标签: bash shell zsh


【解决方案1】:

如果您使用的是 zsh 而不是 bash,您可以使用以下命令启动您的文件:

#!/bin/zsh

此外,true 周围不需要花括号。所以这应该有效:

#!/bin/zsh

if true
then echo "hi"
fi

请注意,您也可以使用bash 运行上述文件。

bash file.sh

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 2019-01-16
    相关资源
    最近更新 更多