[HOW TO] Preserve a custom shell $PATH after logout.

michaelsanford

Translator, Web Developer
I was struggling for some time to come up with an efficient way to add custom folders to the shell $PATH that would be retained after logout.

This is the protocol I came up with.

1. With your favourite editor, create a file called ~/.path

2. In it, add lines of the format:

set path = ( $path /Path_you_wish_to_add )

You can either continue to add lines like this, or better, you can add to that single line every time you have a folder you want to add, separated by a space, with a space after ( and before ).

3. Add the following line to your ~/.tcshrc file (if you don't have one, create it):

source .path

Now, every time you log in, your custom path will be appended to your existing path.

You can change the search order by putting your own folders before or after the $path variable, but unless you have a good reason, don't.

NOTE: You should always add folders to your $PATH using the full path from root. So if you want to add ~/bin add it as /Users/username/bin

I feel this is the more elegant solution, especially if you have multiple-user system, than adding a 'set path = ( $path /custom_path )' in your '~/.login' file, but I suppose you can do that too.
 
Here is a standard way of adding to your PATH:
echo 'setenv PATH "${PATH}:/usr/local/bin:/Developer/Tools:/some/other/path"' >> ~/.tcshrc
source ~/.tcshrc
to have it effective immediately.

You can add it manually with a text editor if you like. As an alternative, you could choose to add it to ~/Library/init/tcsh/path.mine instead of your .*cshrc file, but I prefer to have everything in one compact file for easy backup, portability, and migration from one system to another.
 
I thought the path file was the only one that didn't take a .mine (so ~/Library/init/tcsh/path )?

I tried that first, and I get errors every time I logged in, so I had to do this instead...

I certainly see how you can prefer to have everything in one file; I prefer multiple files myself but that's just me :)
 
Back
Top