[NTLUG:Discuss] PATH variable for beginners
william jones
wljonespe at verizon.net
Mon Feb 19 19:29:46 CST 2007
Someone asked me a question about working with the PATH environment variable in the February Beginner Session. I had not used it in a long time, and did not wish to give outdated misinformation. After checking a few Linux systems at home, I have answers.
To add a new directory: PATH=$PATH:path_to_new_directory. Remember, PATH is the environment variable, $PATH is the address of the variable. Don't forget the colons.
I added a work directory to my HOME directory. The new path is added with PATH=$PATH:~/work
Checked $PATH before the change. It has several directories separated by colons, a space, then the statement No such file or directory. Do not worry about this. Linux will do the right thing with the new addition. The statement will still be at the end of the PATH environment variable.
If done on the command line, this addition to PATH will disappear when Linux is rebooted. To save it, the change must be in a file. The file name varies from distribution to distribution. in the HOME directory it might be .bash_init, .bashrc or .profile. Check the various bash and profile files. One will usually tell the user where PATH changes should be made. If that fails, pick one and give it a try. /etc has other files that will save the change for the whole system. Be careful here. A blunder by user root could bring down the whole system.
It is possible to remove a directory from PATH, but that is a subject for another class.
William L. Jones
More information about the Discuss
mailing list