"command not found" when running a shell script. What did I break?

I'm on OSX Snow Leopard.

Here's the full contents of grr.sh:

#!/bin/sh
echo wow

When I try to run it from terminal:

$ grr.sh
-bash: grr.sh: command not found
$ /bin/sh grr.sh
wow
$ sh grr.sh
wow
$ bash grr.sh
wow

Okay. Fair enough. I'll give it executable permission, then try again:

$ chmod +x grr.sh
$ grr.sh
-bash: grr.sh: command not found
$ chmod 755 grr.sh
$ grr.sh
-bash: grr.sh: command not found

Hmmm. Maybe it'll work if I use bash explicitly? I'll change the file's contents to:

#!/bin/bash
echo wow

And I get the exact same results. What could I have broken?!

One last thing! In case you're curious...

$ which sh
/bin/sh

4 Answers

Absolutely nothing. Only executables in one of the directories in $PATH can be run directly, and . is (usually) never in $PATH. Specify the path to the executable, i.e. ./grr.sh.

3

Is the location of grr.sh in the $PATH variable? If not, you'll need to enter:

./grr.sh

if you are in the same folder as grr.sh. If not, then provide the full path to it.

the permissions for the file are wrong. Try the following commands:

 $ chmod 777 file.sh $ ./file.sh

Yeah, and what ./grr.sh means, is that in this directory, run the command grr.sh. The single . means in the working directory. Otherwise, your shell assumes you are trying to run a command in your $PATH.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like