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
18 # $FreeBSD: src/gnu/usr.bin/man/apropos/apropos.sh,v 1.12.2.2 2002/08/11 11:20:54 ru Exp $
19 # $DragonFly: src/gnu/usr.bin/man/apropos/apropos.sh,v 1.2 2003/06/17 04:25:46 dillon Exp $
22 PATH=/bin:/usr/bin:$PATH
23 db=whatis # name of whatis data base
26 # man -k complain if exit_nomatch=1 and no keyword matched
32 echo "usage: `basename $0` keyword ..." >&2
38 *whatis) grepopt='-w';; # run as whatis(1)
39 *) grepopt='';; # otherwise run as apropos(1)
43 manpath=`%bindir%/manpath -q | tr : '\040'`
44 case X"$manpath" in X)
45 echo "`basename $0`: manpath is null, use \"/usr/share/man\"" >&2
46 manpath=/usr/share/man
51 # reset $PAGER if $PAGER is empty
57 man_locales=`%bindir%/manpath -qL`
59 # search for existing */whatis databases
63 if [ -f "$d/$db" -a -r "$d/$db" ]
65 mandir="$mandir $d/$db"
68 # Check for localized manpage subdirectories
69 if [ X"$man_locales" != X ]; then
72 if [ -f "$d/$l/$db" -a -r "$d/$l/$db" ];
74 mandir="$mandir $d/$l/$db"
81 echo "`basename $0`: no whatis databases in $manpath" >&2
88 if grep -Ehi $grepopt -- "$manpage" $mandir; then :
90 echo "$manpage: nothing appropriate"
94 ( # start $PAGER only if we find a manual page
99 *": nothing appropriate") line2="$line2$line\n";;
100 # matched line or EOF
105 # nothing found, exit
106 if [ -z "$line" -a ! -z "$line2" ]; then
110 ( printf -- "$line2"; echo "$line"; cat ) | $PAGER