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...

The __________ statement is a shorthand notation for a Try statement with a Finally block.

a) Import b) Utilizing c) TryFinally d) Using

Computer Science & Information Technology

The _________ properties are defined in the javafx.scene.shape.Rectangle class.

a. width b. x c. y d. height e. arcWidth

Computer Science & Information Technology

Select the Header row option if you want to include column headings in the sorted table.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

The purpose of creating a ____ is to show placement of the logo, images, text, and other elements to the client before creating the actual artwork.

a. layout b. wireframe c. composition d. parameter

Computer Science & Information Technology