簡體   English   中英

zsh:找不到事件:/bin/bash -- 語法錯誤

[英]zsh: event not found: /bin/bash -- syntax error

文件.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。

需要明確的是,我並不是要你修復我的程序。 出於學習目的,我只是好奇它有什么問題。 我使用{}是因為我弄亂了退出狀態。

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

#!/bin/zsh

此外,不需要在true周圍使用花括號。 所以這應該有效:

#!/bin/zsh

if true
then echo "hi"
fi

請注意,您還可以使用bash運行上述文件。

bash file.sh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM