[ale] BASH: how to refer to first word in command line ?

josin alvistur josin at dimensional.com
Sun Jun 8 18:18:35 EDT 1997


In tcsh I use the following alias to 'cd' to a directory whose
path is in environment variable 'foo':

setenv foo /users/hoser/a_directory

alias foo               'cd ${\!:0}'


This is convenient, since I can have a large number of directory
names so mapped, and i only have to remember the environ var. name
to use the corresponding alias.

and I can use the environ var in the command line, to refer
to the directory:
    example % pwd
              /users/josin
    example & ls -l $foo
  OR
    example % foo; ls -l


QUESTION:
 
How to do the same (or similar) alias setup in bash?

    I tried functions, but the parameter $0 is the script's name,
    *not* the function name (and it defaults to 'bash', if function
    is called from the command line)

    function foo { cd ${$0} }   # does not work...

    and, since we are here, how does one (in the general case) get
    to access the function's name from inside the function ? 

Thanks - josin






More information about the Ale mailing list