BASH: how to refer to first word in command line ?

BASH: how to refer to first word in command line ?

Post by josin alvistu » Mon, 09 Jun 1997 04:00:00



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

 
 
 

BASH: how to refer to first word in command line ?

Post by Andreas Schw » Tue, 10 Jun 1997 04:00:00


|> 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}'

In Bash 2.0, use `shopt -s cdable_vars'.
--
Andreas Schwab                                      "And now for something


 
 
 

1. BASH: command line history-> word substitution????

There must be an easier way to do the following.
[1]# mv OldName.cpp NewName.cpp
[2]# mv OldName.h NewName.h

I know that this works:
[1]# for FILE in OldName.*; do mv $FILE NewName.${FILE##*.}; done

will work, but this is a pain in the butt to type.

I have tried:
[1]# mv OldName.cpp NewName.cpp
[2]# ^cpp^h

and

[1]# mv OldName.cpp NewName.cpp
[2]# !!:s/cpp/h/

but this ONLY substitutes for the first occurrence of cpp! i.e,
mv OldName.h NewName.cpp, which is very wrong.  Is there a way to change the behavior so that
all occurrences of pattern are replaced?

Thanks,

Shea M.

2. Invalid loopback mode

3. How to find the first readable word in one line

4. having trouble on Xwin desktop

5. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

6. looking for newsreader software

7. remsh script - putting output of more than one command / variable on one line

8. sendmail with dial-up access

9. what sed command to print the first line and the last line

10. getting status from first command in a piped command line

11. From as first word in a line in mail

12. catching first words of a multi-line text

13. first word of each line