Write a script cmprpaths that compares the directories specified in CDPATH and PATH, reporting on any that don't appear in both. For example, if

PATH="/bin:/usr/bin/:$HOME/bin"
CDPATH="$HOME/bin:$HOME/projects"

Then the program would report:
$ cmprpaths
/bin appears only in PATH
/usr/bin/appears only in PATH
$HOME/projects appears only in CDPATH
$

There are a number of solutions for this particular script. I took the brute force approach, comparing each of the PATH values to all CDPATH values, then vice versa. There are more efficient solutions too, of course, and changing IFS to ":" also helps ensure that directories with spaces in their path work properly. But that's in Chapter 11.
for pathdir in $( echo $PAT | sed 's/:/ /g')
do
match=0
for cdpathdir in $( echo $CDP | sed 's/:/ /g')
do
if [ "$cdpathdir" = "$pathdir" ] ; then
match=1
fi
done
if [ $match -eq 0 ] ; then
echo "$pathdir appears only in PATH"
fi
done

## then we do the same thing, but with the two variables swapped

for cdpathdir in $( echo $CDP | sed 's/:/ /g')
do
match=0
for pathdir in $( echo $PAT | sed 's/:/ /g')
do
if [ "$cdpathdir" = "$pathdir" ] ; then
match=1
fi
done
if [ $match -eq 0 ] ; then
echo "$cdpathdir appears only in CDPATH"
fi
done

Computer Science & Information Technology

You might also like to view...

A ________ displays in the lower left corner of the slide while the slide show is running

A) status bar B) navigation toolbar C) Mini toolbar D) Quick Access toolbar

Computer Science & Information Technology

Word's ________ feature permits you to select text then point to a font to see effect of the font on the text

A) Live Layout B) Live Preview C) WordArt D) Style

Computer Science & Information Technology