This will give exec permission to user, group and other, so beware of possible security issues. To restrict permission to a single access class, you can use:
In MacOS Catalina, Apple has replaced bash with zsh as default shell. This can mean, that they intend to remove bash in the future, so this might not be an option later, but with Catalina it still works.
Starting with macOS Catalina,
Your Mac uses zsh as the default login shell and interactive shell. You can make zsh the default in earlier versions of macOS as well.
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.
Another annoying error can be n typo in the sh script.
In the following example, the ZSH error message does confusing. ZSH does tell you zsh: permission denied: startup.sh. But you have access rights to your script. The issue is the invalid Shebang line in the script:
My file permissions before making the below change were -rwxr-xr-x. Even though I had the execute permission but still i got the permission denied error.
I am using vs code editor. I executed chmod +x filename and the file permissions still remained the same. The only difference this time was that I was able to run the file. Something changed about the file but it's not visible. The reason why I say it's not visible is that in the source control tab of my editor, my new file and old file looked 100% the same. If I stash my changes and execute the file then again same error.
I don't know why and how it worked but it's worth a try.
I will be more than happy if someone can explain the reason to me why it did not work earlier as I had the same permissions? Also, what changed in my file which is not visible to me?