A tool to make writing .cshrc files (and their cousins) easier.


addpath [-cbw] [-df] [-e var] [-p var] elem ...


addpath appends a set of new paths to your PATH (or other) environment variable. It checks for duplicates, so that a new element will not be added if it is in the PATH already.

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

		I want to try this with a different JDK

	% setenv JDK_HOME /opt/java/jdk117
	% csh
		I want this to happen
	% echo $PATH
The 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 )
This 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'`


emit path in Bourne shell style, using : as a delimiter. (default for most shells)
emit path in C-sh style. That is, with spaces rather than colons. (default when SHELL ends in "csh"
emit path in windows style. That is, semicolon and backslash
allow Duplicates. Normally addpath will not add elements which are in the path already
put new elements at the Front of the PATH
-e var
only do it if Environment variable var is defined.
-p var
Use var rather than PATH.
emit an output that you could "source" (or eval) back into your shell. Thuu eval `addpath -s '$ANT_HOME/bin'` should work in all shells
Check new path elements for existance (as directories) before adding.


Tony Aiuto (


You can find the source at