addpath [-cbw] [-df] [-e var] [-p var] elem ...
One might think, "Big whoop, why can't you just get your path right in your .cshrc file and be done with it?" Well, I'll tell you. I work in an environment where I can log into the same home directory from many different platforms, even (gasp!) non-unix ones, like windows. We strive to maintain single file system image accross a ridiculous number of machines. With good NFS automounting, many binaries are in the same relative place on all platforms, but we can't get it right for everything. Worse, we use multiple versions of various tools on several platforms, so that we want to constantly switch our paths. Thus, this need often arises:
% echo $PATH /users/tony/bin:/usr/local/bin:/bin:/usr/bin:/opt/java/jdk200/bin I want to try this with a different JDK % setenv JDK_HOME /opt/java/jdk117 % csh I want this to happen % echo $PATH /users/tony/bin:/usr/local/bin:/bin:/usr/bin:/opt/java/jdk116/binThe practical solution is to do something like this:
# .cshrc set path = ( $HOME/bin /usr/local/bin /bin /usr/bin ) if ( $?JDK_HOME ) then set path = ( $path $JDK_HOME/bin ) endifThis works fine up to a point. If you try, howerver, to add something to your path by hand, and then invoke the shell again, it gets lost. What you really want is to be able to set JDK_HOME in the environment and have your shell .rc file add $JDK_HOME/bin to your path only if it needs it. With addpath we can do this
# .cshrc # make sure that these are in the path, without # disturbing other items set path = `addpath -cf $HOME/bin /usr/local/bin /bin /usr/bin` # add the JDK toolkit to the front of the path if we have it set path = `addpath -f -e JDK_HOME '$JDK_HOME/bin'` # or use the shorthand. This works because if JDK_HOME is not in # the environment, addpath will skip the element which references it set path = `addpath -f '$JDK_HOME/bin'` # or use the portable method that works for both Bourne and C shells eval `addpath -sf '$JDK_HOME/bin'`