A reader writes:
“I’ve got a few of your books and today picked up Wicked Cool Shell Scripts, which I’m very much looking forward to working with.
“Totally greenhorn question, though: I want to keep the scripts in ~/bin and on page 12 you have an italic note saying to edit our PATH variable, but I’m not sure how, and don’t see any instructions anywhere else as to how to do this. I would be perfectly happy to have ~/scripts as you suggest but have not been able to create either. Your other book
Learning Unix for Mac OS X doesn’t appear to show how to do this with BASH. Many thanks in advance.”
The standard way to alter your PATH is to add a line to your ~/.bash_login, ~/.profile or ~/.login file (depending on which shell you’re using). Bash will read either of the first two filenames, but let’s use ~/.bash_login for consistency sake.
Open up that file (or create one if you don’t have it yet) by using vi, pico, emacs, jove, or whatever else is your favorite editor in Terminal.app. Then append your desired directory to the end of the existing PATH value like so:
export PATH="${PATH}:/Users/joe/bin"
Close that terminal window and open another (File -> New Shell), then type echo $PATH and you should see your specified path appended to the end. Then just make sure you have that directory (you can use mkdir ~/bin to create it if needed).
Now you can drop scripts and programs into that file to your heart’s content, and they’ll automatically be found when you type in their names to the shell.
Note that there’s a slight variation on this that can work too, and that might be more commonly used, as demonstrated by this actual entry in my own ~/.bash_login file:
PATH="${PATH}:/sw/bin:/usr/X11R6/bin:/Users/taylor/bin"; export PATH
Hope that helps clear things up!