Followup to "whatis" returns 0 for missing commands, I am trying to modify /usr/bin/whatis
to return a non-zero exit code after an inappropriate command has been entered. My approach to doing this is to add a return variable in the following segment, and return that variable after the end of the loop
while [ "$1" != "" ]
do
found=0
for d in /var/cache/man $manpath /usr/lib
do
if [ -f $d/whatis ]
then
if grep -"$grepopt1" "$grepopt2""$1" $d/whatis
then
found=1
fi
fi
done
if [ $found = 0 ]
then
echo "$1: nothing appropriate"
**code=1**
fi
shift
done | eval ${PAGER:-more -E}
**return $code**
However, since the while
loop is piped into eval
, it is run in a subshell so code
will not be assigned outside the while
loop. I have tried multiple different methods, however, these are all about piping a value INTO the while
loop, not piping a value out of the while
loop.
A workaround I found is simply removing the entire eval
statement, but I would like a method that preserves the original extensibility of whatis