Running a heterogeneous environment is always a challenge. Having an enterprise with AIX, IRIX, HPUX, Ultrix, Solaris, and several flavors of Linux, what is a good universal PATH setting that allows a good common set of commands, but also includes the extras, like 'ifconfig', 'ping', and 'make' that are often not there by default?
In particular, you don't want to be adding to $PATH blindly in .bashrc or you end up with a mess on a sub-sub-sub-sub shell. You want to include all the sbin directories, because important tools can be there. You want to include /usr/ccs/bin:/usr/ucb as Solaris puts a few things you're likely to use in there.
Notably missing are the infinite permutations of choices for local installations of software, e.g. the GNU tools - usually you want them in the PATH before the system versions. Also, I left out directories that are more likely to be useful as a historical curiousity, like /etc and /usr/libexec.
It's endlessly debatable whether the Solaris /usr/ccs/bin should be before or after the GNU versions of the utilities. Realistically, you'll have occasional problems because of this no matter which way you choose.
I use a combination of checks and tests to set my path on any given system via my .bashrc/.profile:
First - set a basic path which should be valid anywhere. Then you need to know where you're running:
Then you can add OS specific paths:
Where ck_add2path is defined as:
For the
root
user, I'd be very careful; and by that I mean to not try and use a common PATH, do it per OS if you have to.A little extra work, but you don't want any surprises.
For non-
root
, there's so many...The problem I've had in the past, specially with AIX, is that for some commands, you want your 3rd party install to take precedence, so then you place /opt/bin before /bin for example. Later things break because other utilities rely on the PATH to give them the native tool in /bin/.
They're 'there' but often in /sbin and/or /usr/sbin. My .bashrc includes:
I'd started with saving my old path before modifying it, so that subsequent calls to my startup scripts would not result in ever increasing PATH values... But after a while I ended up just setting it to a nice empirically established baseline.
I wanted X11 (even if only to call eval
resize
on remote ssh sessions to establish COLUMNS and LINES environment variables)I added /usr/css/bin because some of my bare solaris installs didn't have make in the path (and even fewer even had cc or gcc!)
Of course the /usr/local/ set of paths were added, and then stuff in my homedir (both with and without architecture specific paths) and '.'.
The line with '.' in the path is questionable if you are root however.
This setup has served me well across AIX, HPUX, IRIX, Ultrix, Solaris and Linux so far. Maybe even on those ancient apollo's (anyone see /usr/5bin anymore?)
I second dsully's programmatic approach for testing directories and adding paths. Also, when I add
$dir
to$PATH
, I normally add$dir/../man
to$MANPATH
(if it exists).