home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / bin / whatis < prev    next >
Encoding:
Text File  |  1995-06-08  |  1.7 KB  |  103 lines

  1. #!/bin/sh
  2. #
  3. # whatis -- search the whatis database for keywords.  Like apropos,
  4. #           but match only commands (as whole words).
  5. #
  6. # Copyright (c) 1990, 1991, John W. Eaton.
  7. #
  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
  10. # distribution.  
  11. #
  12. # John W. Eaton
  13. # jwe@che.utexas.edu
  14. # Department of Chemical Engineering
  15. # The University of Texas at Austin
  16. # Austin, Texas  78712
  17. #
  18. # whatis-1.4 aeb 941007
  19. #
  20.  
  21. PATH=/usr/local/bin:/bin:/usr/ucb:/usr/bin
  22.  
  23. libdir=/usr/lib
  24.  
  25. if [ $# = 0 ]
  26. then
  27.     echo "usage: `basename $0` name ..."
  28.     exit 1
  29. fi
  30.  
  31. manpath=`/usr/bin/man --path | tr : '\040'`
  32.  
  33. if [ "$manpath" = "" ]
  34. then
  35.     echo "whatis: manpath is null"
  36.     exit 1
  37. fi
  38.  
  39. if [ "$PAGER" = "" ]
  40. then
  41.     PAGER="/usr/bin/less -s"
  42. fi
  43.  
  44. # avoid using a pager if only output is "nothing appropriate"
  45. nothing=
  46. found=0
  47. while [ $found = 0 -a -n "$1" ]
  48. do
  49.     for d in $manpath /usr/lib
  50.     do
  51.         if [ -f $d/whatis ]
  52.         then
  53.             if grep -iws "^$1" $d/whatis
  54.             then
  55.                 found=1
  56.             fi
  57.         fi
  58.     done
  59.     if [ $found = 0 ]
  60.     then
  61.     nothing="$nothing $1"
  62.     shift
  63.     fi
  64. done
  65.  
  66. if [ $found = 0 ]
  67. then
  68.     for i in $nothing
  69.     do
  70.     echo "$i: nothing appropriate"
  71.     done
  72.     exit
  73. fi
  74.  
  75. while [ $1 ]
  76. do
  77.     for i in $nothing
  78.     do
  79.     echo "$i: nothing appropriate"
  80.     done
  81.     nothing=
  82.     found=0
  83.     for d in $manpath /usr/lib
  84.     do
  85.         if [ -f $d/whatis ]
  86.         then
  87.             if grep -iw "^$1" $d/whatis
  88.             then
  89.                 found=1
  90.             fi
  91.         fi
  92.     done
  93.  
  94.     if [ $found = 0 ]
  95.     then
  96.         echo "$1: nothing appropriate"
  97.     fi
  98.  
  99.     shift
  100. done | $PAGER
  101.  
  102. exit
  103.