"whatis" returns 0 for missing commands

Solution 1:

On macOS whatis is just a shell script.

$ type whatis
whatis is hashed (/usr/bin/whatis)
$ file /usr/bin/whatis
/usr/bin/whatis: POSIX shell script text executable, ASCII text

If you look inside, the relevant part reads

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"
    fi

    shift
done | eval ${PAGER:-more -E}

So if no entries are found (the if [ $found = 0 ] part), the message is displayed without setting any exit code. Actually the script only exits with status 1 if wrong arguments have been passed.

The most recent update notice relates to 2003-08-01 as the date of update, so it seems to be rather old anyway. Whether the behaviour is a feature or a bug is open for discussion.


In case you are wondering about apropos showing the same behaviour: apropos and whatis are basically the same script.

$ ll /usr/bin/{apropos,whatis}
-r-xr-xr-x  1 root  wheel  1808 Aug 18 00:18 /usr/bin/apropos*
-r-xr-xr-x  1 root  wheel  1806 Aug 18 00:18 /usr/bin/whatis*
$ diff /usr/bin/{apropos,whatis}
26,27c26,27
< grepopt1=$aproposgrepopt1
< grepopt2=$aproposgrepopt2
---
> grepopt1=$whatisgrepopt1
> grepopt2=$whatisgrepopt2