March 2002
Beginner
504 pages
10h 47m
English
| 1: | Write a function that determines whether a command is located in one of the directories in $PATH. The command will be supplied as the first argument. If the command is located in one of the directories in $PATH, your function should print the full path to the command and return 0. Otherwise your function should return 1 and optionally print an error message. |
| A1: | A possible implementation is
inPath () {
OLDIFS="$IFS"
IFS=:
RC=1
for i in $PATH
do
if [ -x "$i/$1" ] ; then
echo "$i/$1"
RC=0
break
fi
done
IFS="$OLDIFS"
return $RC
}
|
| 2: | Write a function to make a directory (and all of its parents) change to that directory and then print the full path of that directory. Please include error checking at all levels. Make sure that your function ... |
Read now
Unlock full access