Table of Contents
A shell is the program that takes what you type at the keyboard and interprets, then eventually executes a command. A shell can do a number of things to make your environment easier, such as doing command line completion, performing substitutions, allowing you to set variables and more.
An environment variable is a shell variable that gets inherited by all of the processes spawned by the shell that first set it. For instance, if I set the environment variable FOO, and then ran the program make, make would then have access to the variable FOO that I had set.
How to set an environment variable depends on which shell you are running. (t)csh sets an environment variable with the following syntax:
setenv VARIABLE value
With bourne and POSIX shells (such as sh, bash, zsh, ksh), you set an environment variable like this:
VARIABLE=value ; export VARIABLE
csh and tcsh read a number of files when they startup. You can put things in these files and they will be sourced when you login.
Here is a list of the files these shells read when they startup. The list is in the order in which the files are read(to the best of my knowledge):
/etc/csh.cshrc
Sources /usr/share/init/tcsh/rc
/etc/csh.login
Sources /usr/share/init/tcsh/login
$HOME/.cshrc
$HOME/.tcshrc (tcsh only, and only if .cshrc doesn't exist)
$HOME/.login
And when you logout, it reads:
/etc/csh.logout
Sources /usr/share/init/tcsh/logout
$HOME/.logout
Under Darwin, the global default files in /etc actually source files in /usr/share/init/tcsh
You should edit your $HOME/.cshrc file to set your path every time you login. The simple way to set your path is to add a line like this to your .cshrc file:
set path=(/bin /usr/bin /sbin /usr/sbin /usr/local/bin /usr/local/sbin)
The directories listed within the parentheses will then be included in your path, and you can execute any program within those directories. Be careful what order you put the directories in. If a program has the same name, in different places, the first one to appear in your path will be the one used. So, if you had /bin/ls and /usr/local/bin/ls, with the path above when you type ls, /bin/ls will be executed.
If you want to make sure only directories that exist are in your path, you can use something like this:
set p=() foreach x ( /directory /list ) if (-d $x) set p=( $p $x ) end set path = ( $p ) unset p
This will try every directory listed in the ( /directory /list ) section, and if that directory exists on your system, it will be added to your path.
If you use (t)csh and you have setup your path as I recommend in the above section, then you should just add the new directory to your .cshrc file.
If you just want to add a directory to your path on the command line, with (t)csh, you can use:
set path = ( $path /tmp )
With a Bourne shell syntax you can use:
PATH="$PATH:/tmp"; export PATH
These will both add /tmp to the end of your path.