% ./script.sh
zsh: permission denied: ./script.sh
If you are trying to execute a script on the Terminal using the Zsh shell and you get permission denied then make sure that the script has the execute permissions. You can do that by using the ls command.
% ls -ltrh
total 2832
-rw-r--r-- 1 code2care staff 5B Jul 19 11:50 script.sh
Adding execute permission to the file:
Use the chmod command to add execute (x) permissions to the script.
chmod +x script.sh
Now if I try to run the script again it works!
% ./script.sh
Hello, World!
bash startup.sh
# How to change your default shell Whether your user account is configured to use zsh (recommended), bash, or another shell, you can change the default shell from Users & Groups preferences or the command line.
From Users & Groups preferences
Choose Apple menu > System Preferences, then click Users & Groups.
Click the lock , then enter your account name and password.
Control-click your user name in the list of users on the left, then choose Advanced Options.
Choose a shell from the ”Login shell” menu, then click OK to save the changes.