views:

33

answers:

4

I am on Mac's OS 10.6, and I am trying to learn a thing or two about shell scripting. I understand how to save a shell script and make it executable, but I am wondering what I can do or where I can save the file to make it global (that is, accessible no matter what folder I am in).

For example, if I save a .sh file in the /Users/username/ directory and make it executable, I can only execute that script in that specific directory. If I navigate to /Users/username/Downloads, for example, I can't execute the script.

Also, any suggestions of resources for learning more about shell scripting would be helpful. Thanks

A: 

You should put it in the global executable directory on your machine. I think that would usually be /usr/bin on Unix-based operating systems (this would however most often require super user privileges on that machine).

You could also put it in any other directory that is in the $PATH environment variable, although it would only work for those users who have that directory in that variable.

You can find the value of $PATH by typing echo $PATH in a shell. The directories are separated by :.

Frxstrem
I'm gonna downvote because /usr/bin is the wrong answer. /usr/local/bin is specifically designed for "local" scripts (ie: ones you create rather than ones that come with the system).
Bryan Oakley
A: 

Either saving it in /usr/bin (or any other directory present in PATH) or editing PATH to include the directory you saved it in will basically make it run in any directory.

You
`/usr/bin` can be completely emptied and replaced during an OS upgrade, making your script mysteriously disappear. `/usr/local/bin` is for this purpose, as mentioned by Bryan Oakley. Also see the [Filesystem Hierarchy Standard](http://www.pathname.com/fhs/pub/fhs-2.3.html#USRLOCALLOCALHIERARCHY)
Stephen P
A: 

/usr/local/bin would be the most appropriate location. Mac OS X has it in the PATH by default

unbeli
+5  A: 

Traditionally, such scripts either go in ~/bin (ie: the bin directory in your home directory) or /usr/local/bin/ The former means the script will only work for you, the latter is for scripts you want anybody on the system to be able to run.

If you put it in ~/bin, you may need to add that to your PATH environment variable. /usr/local/bin should already be on the path.

Bryan Oakley