Setting PATH

When you type in the name of a program, the unix system looks at what is known as your PATH to find that program. Your PATH is a list of directories seperated from each other with a ":". Path directories are searched one at a time for the command starting with the first one. As soon the command is found the search stops and the command is executed.

One of the entries in your PATH is a ".", this "." stands for current directory and should always be near or at the end of your path. Otherwise if you type in a command name which happens to be the name of a program or file in your current directory you will inadvertanly run the wrong program.

To see what you path currently is run the command echo $PATH If you want to add a directory to your path for example /opt/intel80/bin then

  • If it as a temporary change only needed while you are logged in this time use the command
    export PATH=$PATH:/opt/intel80/bin
    
    in each terminal window you need the change to work from.
  • If you want to make the change permanently you need edit your .bashrc file which is in your homedirectory and add the line above to the end of the file, making sure it is under the line
    # Add personal customisation commands after this line ------------------
    
    Now tell the system to rerun your .bashrc file with the command
            . ~/.bashrc 
    
    this will make the change in the window you run the command from. Next time you log in the system will pick up your new path automatically.

    The above is written for bash users which is the default shell in damtp. Should you be a C shell user (csh or tcsh) ie not using the default shell then you must note the following differences for c-shell.

    • You must type path for PATH
    • The components of your path are seperated by a blank space not a :
    • you use set instead of export
    • the file you edit is called .cshrc not .bashrc
    • you use the command source not "." to rerun your .cshrc file

    Useful Link



    Please email any suggestions, corrections, broken links, or errors to itweb [itweb@damtp.cam.ac.uk]