3
Anakata
4y

I wasn’t able to run a bash script right now using ./script.sh as I was getting an error “Command not found.” I tried running it using source command instead of ./ and it worked! What’s going on here?

Comments
  • 2
    Guess your hashbang is wrong.
  • 0
    @metamourge my Mac is using Zsh. And the script is in bash (I forked the repository from GitHub). Could that be the reason?
  • 0
    @srpatil
    Just look if the hashbang is a valid path on your system,
    If not, change it.
  • 0
    Change the shebang to #!/usr/bin/env bash, if it happens to be the issue. This will make the script more portable.
  • 0
    It can also be the line termination character...
  • 3
    Did you chmod +x it?
  • 0
    @phorkyas yup! And that worked😄
  • 2
    @srpatil weird, lack of executable permition yelds a 'permission denied' kind of error in linux. It's weird to see that mac gives you a not-found err instead :)
  • 2
    @netikras yes I got “permission denied” message at first. So I ran the file using sudo ./ which prompted me to enter the password after which it gave the “command not found” error message.
Add Comment