Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a shell script global?

Tags:

shell

unix

macos

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

like image 594
zebraman Avatar asked Aug 24 '10 19:08

zebraman


2 Answers

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

like image 164
unbeli Avatar answered Sep 19 '22 06:09

unbeli


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.

like image 43
Bryan Oakley Avatar answered Sep 19 '22 06:09

Bryan Oakley