Finding The Right Man (Page)

by Chris Josephes


I work in multiple Unix flavor environments. Sometimes commands on one host aren't where I expect them to be on another. In one or two cases, my PATH variable could have 8 directories for me to search.



A long time ago, I wrote a .bashrc script to build my PATH based on what's actually available on the host system.



# Set the path
PATH=""
PATHLIST="
/opt/subversion/bin
/opt/perl5/bin
/opt/security/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sfw/bin
/opt/sfw/bin
/usr/ccs/bin
/opt/SUNWspro/bin
/usr/ucb
/opt/mysql/bin
/home/chrisj/bin
"
for p in $PATHLIST
do
if [ -d $p ]; then
PATH=$PATH$p:
fi
done


It goes from specific directories, to root access directories, to common directories, then least used directories. If the directory doesn't exist, it won't be in the PATH variable.



That worked fine for awhile, but I had a problem with manpages. Some manpages on certain commands wouldn't reflect the actual command I'm calling. I made another modification to the script to build a dynamic MANPATH.



# Set the manpath
MANPATH=""

for m in $PATHLIST
do
BASE=`dirname $m`
if [ -d $BASE/man ]; then
MANPATH=$MANPATH$BASE/man:
fi
done


If there's a manpage directory outside of the scope of PATHLIST, just add it to the end of the variable in the form of "/path/to/bin". If the bin directory doesn't exist, it won't be added to the command search path. But, if the corresponding man path exists, it will be added.