"whatis" returns 0 for missing commands On macOS 10.14, using whatis on a command that is not installed prints 'command': nothing appropriate as is expected.  But returns 0 instead of an error code, which I believe is expected behavior.  It is also not consistent with man, which returns 1 after no results.  Additionally, whatis prints to stdout, while man prints to stderr.

This is different than Linux, which returns an error code, and prints to stderr.

macOS:

$ whatis abc; echo $?
abc: nothing appropriate
0

$ man abc; echo $?
No manual entry for abc
1

$ whatis abc 2&gt;/dev/null
abc: nothing appropriate

$ man abc 2&gt;/dev/null


Linux (Ubuntu):

$ whatis abc; echo $?
abc: nothing appropriate.
16

$ man abc; echo $?
No manual entry for abc
16

$ whatis abc 2&gt;/dev/null

$ man abc 2&gt;/dev/null


I believe whatis should not return 0 when it fails to find a description of the command, and should have behavior consistent with man

Note: I noticed this because I'm writing a program that relies on this functionality

Edit: apropos has the same behavior as whatis
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
&lt; grepopt1=$aproposgrepopt1
&lt; grepopt2=$aproposgrepopt2
---
&gt; grepopt1=$whatisgrepopt1
&gt; grepopt2=$whatisgrepopt2