[vox-tech] Bash completion mystery

Wes Hardaker wjhns156 at hardakers.net
Fri Feb 24 07:55:32 PST 2012


>>>>> On Thu, 23 Feb 2012 19:51:27 -0800, Bryan Richter <bryan.richter at gmail.com> said:

BR> Functions can be discovered with 'declare -f'.

The problem with todays environment is that there is real-executables,
aliases and functions.  Aliases are pretty much lame in bash so everyone
uses functions (which can take arguments, etc).

But in the end, there are in fact 3 places to look for a definition.  So
about a month ago I wrote this:

    wh()       {
        prog="$1"
        if [ "`declare -F $prog`" != "" ] ; then
            declare -f $prog
        elif alias $prog > /dev/null 2>&1 ; then
            alias $prog
        else
            which $prog
        fi
    }

Which if you use in replace of `which` checks all three sources and
reports the definition or location to you.

  # wh ifconfig
  /sbin/ifconfig

  # wh wh
  wh () 
  { 
      prog="$1"
      ...

-- 
Wes Hardaker                                     
My Pictures:  http://capturedonearth.com/
My Thoughts:  http://pontifications.hardakers.net/


More information about the vox-tech mailing list