# How to run a shell script



## lloyd709 (Nov 18, 2008)

I want to run a basic shell script (to create a large number of directories) but when I try to run a simple test version of it I get "command not found".

I've created the text file and made it executable using the chmod +x command so I don't understand why it doesn't run when I type it's name.

It's the first time I've tried to run a shell script on my Mac (years and years ago I used to run them on a Unix system though) so I expect I'm doing something very basic wrong but can't think what.


----------



## macbri (Nov 18, 2008)

You probably need to put the path to your script.

If it's in your current directory do:

    ./yourscript

Or put a full path:

    /path/to/yourscript


----------



## lloyd709 (Nov 18, 2008)

Thanks, that worked.  I thought that you could just type the name of the file if it's in your current directory - I didn't think you had to put ./ in front of it.  Such a simple thing but it was driving me mad.


----------



## ElDiabloConCaca (Nov 18, 2008)

If your current directory is in your $PATH global, then that would work -- otherwise, you always have to specify the directory.

You CAN put a directive in your $PATH global indicating the current directory so that you can run scripts located in whatever directory you're in without the ./ at the front, but this is advised against due to security reasons (for example, if a hacker put an 'ls' binary in your current directly, and you executed 'ls' thinking you're getting a directory listing, then the hacker's 'ls' would be executed instead).


----------



## lloyd709 (Nov 18, 2008)

Thanks


----------

