3 # apropos -- search the whatis database for keywords.
5 # Copyright (c) February 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
6 # Copyright (c) 1990, 1991, John W. Eaton.
8 # You may distribute under the terms of the GNU General Public
9 # License as specified in the README file that comes with the man
14 # Department of Chemical Engineering
15 # The University of Texas at Austin
21 PATH=/bin:/usr/bin:$PATH
22 db=whatis # name of whatis data base
25 # man -k complains if exit_nomatch=1 and no keyword matched
31 echo "usage: `basename $0` keyword ..." >&2
37 *whatis) grepopt='-w';; # run as whatis(1)
38 *) grepopt='';; # otherwise run as apropos(1)
42 manpath=`%bindir%/manpath -q | tr : '\040'`
43 case X"$manpath" in X)
44 echo "`basename $0`: manpath is null, using \"/usr/share/man\"" >&2
45 manpath=/usr/share/man
50 # reset $PAGER if $PAGER is empty
56 man_locales=`%bindir%/manpath -qL`
58 # search for existing */whatis databases
62 if [ -f "$d/$db" -a -r "$d/$db" ]
64 mandir="$mandir $d/$db"
67 # Check for localized manpage subdirectories
68 if [ X"$man_locales" != X ]; then
71 if [ -f "$d/$l/$db" -a -r "$d/$l/$db" ];
73 mandir="$mandir $d/$l/$db"
80 echo "`basename $0`: no whatis databases in $manpath" >&2
87 if grep -Ehi $grepopt -- "$manpage" $mandir; then :
89 echo "$manpage: nothing appropriate"
93 ( # start $PAGER only if we find a manual page
98 *": nothing appropriate") line2="$line2$line\n";;
104 # nothing found, exit
105 if [ -z "$line" -a ! -z "$line2" ]; then
109 ( printf -- "$line2"; echo "$line"; cat ) | $PAGER