| Line | |
|---|
| 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 | #
|
|---|
| 12 |
|
|---|
| 13 | whatis()
|
|---|
| 14 | {
|
|---|
| 15 | local wusage='usage: whatis arg [arg...]'
|
|---|
| 16 | local fail=0
|
|---|
| 17 |
|
|---|
| 18 | if [ $# -eq 0 ] ; then
|
|---|
| 19 | echo "$wusage"
|
|---|
| 20 | return 1
|
|---|
| 21 | fi
|
|---|
| 22 |
|
|---|
| 23 | for arg
|
|---|
| 24 | do
|
|---|
| 25 | case $(builtin type -type $arg 2>/dev/null) in
|
|---|
| 26 | "alias")
|
|---|
| 27 | builtin alias "$arg"
|
|---|
| 28 | ;;
|
|---|
| 29 | "function")
|
|---|
| 30 | builtin type "$arg" | sed 1d
|
|---|
| 31 | ;;
|
|---|
| 32 | "builtin")
|
|---|
| 33 | echo builtin "$arg"
|
|---|
| 34 | ;;
|
|---|
| 35 | "file")
|
|---|
| 36 | builtin type -path "$arg"
|
|---|
| 37 | ;;
|
|---|
| 38 | *)
|
|---|
| 39 | # OK, we could have a variable, or we could have nada
|
|---|
| 40 | if [ "$(eval echo \${$arg+set})" = "set" ] ; then
|
|---|
| 41 | # It is a variable, and it is set
|
|---|
| 42 | echo -n "$arg="
|
|---|
| 43 | eval echo '\"'\$$arg'\"'
|
|---|
| 44 | else
|
|---|
| 45 | echo whatis: $arg: not found
|
|---|
| 46 | fail=1
|
|---|
| 47 | fi
|
|---|
| 48 | ;;
|
|---|
| 49 | esac
|
|---|
| 50 | done
|
|---|
| 51 | return $fail
|
|---|
| 52 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.