what.sh 708 B

1234567891011121314151617181920
  1. function what () {
  2. # Show what command will run when $1 is typed
  3. if [ $# -ne 1 ]; then
  4. echo "$FUNCNAME: Usage: $FUNCNAME COMMAND|--help" 1>&2
  5. return
  6. fi
  7. if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "help" ]; then
  8. echo "$FUNCNAME: Show what command will run when $1 is typed"
  9. echo "$FUNCNAME: Bash executes aliases, functiions and binaries on path, in that order"
  10. echo "$FUNCNAME: Usage: $FUNCNAME COMMAND" 1>&2
  11. return
  12. fi
  13. alias | grep -i "alias $1=" || \
  14. declare -f $1 || \
  15. compgen -b $1 || \
  16. which $1 || \
  17. echo "$FUNCNAME: $1 is unknown. Not on path, an alais, builtin or a function" 1>&2
  18. }