简体   繁体   中英

zsh: event not found: /bin/bash -- syntax error

file.sh

#!/bin/bash

if { true }
then echo "hi"
fi

I have this within a shell-script. Upon trying to run, I get:

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

Running in my shell:

% #!/bin/bash

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

Running again in my shell:

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

so the issue is with !/bin/bash . Anyone know what's going on? I looked online but all the posts on it are far in the past and it seems like the users weren't doing this inside a file/shellscript.

I am on MacOS Ventura, running zsh.

To be clear, I'm not asking you to fix my program. I'm just curious what's wrong with it as is, for learning purposes. I'm using {} because I was messing with the exit statuses.

If you are using zsh instead of bash, you can start your file with:

#!/bin/zsh

Also, there is no need for curly braces around true . So this should work:

#!/bin/zsh

if true
then echo "hi"
fi

Note that you can also run the above file with bash .

bash file.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM