Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 1 | # |
| 2 | # whatis -- and implementation of the 10th Edition Unix sh builtin `whatis' |
| 3 | # command. |
| 4 | # |
| 5 | # usage: whatis arg [...] |
| 6 | # |
| 7 | # For each argument, whatis prints the associated value as a parameter, |
| 8 | # builtin, function, alias, or executable file as appropriate. In each |
| 9 | # case, the value is printed in a form which would yield the same value |
| 10 | # if typed as input to the shell itself. |
| 11 | # |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 12 | # |
| 13 | # Chet Ramey <chet.ramey@case.edu> |
| 14 | # |
| 15 | # Copyright 1994 Chester Ramey |
| 16 | # |
| 17 | # This program is free software; you can redistribute it and/or modify |
| 18 | # it under the terms of the GNU General Public License as published by |
| 19 | # the Free Software Foundation; either version 2, or (at your option) |
| 20 | # any later version. |
| 21 | # |
| 22 | # TThis program is distributed in the hope that it will be useful, |
| 23 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | # GNU General Public License for more details. |
| 26 | # |
| 27 | # You should have received a copy of the GNU General Public License |
| 28 | # along with this program; if not, write to the Free Software Foundation, |
| 29 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 30 | |
Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 31 | |
| 32 | whatis() |
| 33 | { |
| 34 | local wusage='usage: whatis arg [arg...]' |
| 35 | local fail=0 |
| 36 | |
| 37 | if [ $# -eq 0 ] ; then |
| 38 | echo "$wusage" |
| 39 | return 1 |
| 40 | fi |
| 41 | |
| 42 | for arg |
| 43 | do |
| 44 | case $(builtin type -type $arg 2>/dev/null) in |
| 45 | "alias") |
| 46 | builtin alias "$arg" |
| 47 | ;; |
| 48 | "function") |
| 49 | builtin type "$arg" | sed 1d |
| 50 | ;; |
| 51 | "builtin") |
| 52 | echo builtin "$arg" |
| 53 | ;; |
| 54 | "file") |
| 55 | builtin type -path "$arg" |
| 56 | ;; |
| 57 | *) |
| 58 | # OK, we could have a variable, or we could have nada |
| 59 | if [ "$(eval echo \${$arg+set})" = "set" ] ; then |
| 60 | # It is a variable, and it is set |
| 61 | echo -n "$arg=" |
| 62 | eval echo '\"'\$$arg'\"' |
| 63 | else |
| 64 | echo whatis: $arg: not found |
| 65 | fail=1 |
| 66 | fi |
| 67 | ;; |
| 68 | esac |
| 69 | done |
| 70 | return $fail |
| 71 | } |