I put the below script in a file called "volume", and put that file in a folder within $PATH. I can execute it fine by "bash thatpath/volume 10" but when I try to execute it using just "volume 10" from anywhere I get "/bin/bash: bad interpreter: Operation not permitted". The file's permissions are 755.
#!/bin/sh
FIRST_ARGUMENT="$1"
echo "Set volume to $FIRST_ARGUMENT!"
osascript -e "set volume output volume $FIRST_ARGUMENT" 4 2 Answers
I read some similar issue and they also noted that the line endings might be messed up. So I started a new file and typed that all once more and saved. +x:ed it and it started working. So I guess yes, the line endings were the culprit. I did edit the file first time with TextEdit, it shouldn't give Windows line endings but um anyway it's fixed now.
For posterity, I hit this on my Mac after renaming a shell file in Finder that was open in BBEdit. Then, when I modified the file in BBEdit (which correctly reflected the new filename) and saved, I could no longer run the script.
For me, the fix was as simple as quitting BBEdit and re-launching, then saving the file once more. 🤷‍♂️
My issue was happening regardless of whether or not arguments were included.