How can I pass a command line argument to an aliased command?

How can I pass a command line argument to an aliased command?

Post by Mark » Sat, 21 Sep 2002 05:22:51



How can I pass a command line argument to an aliased command?

In this example, I want to pass a candidate directory name as a command line
argument and have it processed by the "dir" alias script.

For example:

arvant02:/opt/vantive8> alias dir='ll -F omu | egrep ^d '
arvant02:/opt/vantive8> dir
drwxrwxr-x       2 vantive    dba           2048 Aug  9  2001 apps_ora8/
drwxrwxrwx       2 vantive    dba           2048 Apr 26 11:46 backup/
drwxrwxrwx       2 oracle     dba             96 Oct  9  2001 core_22352/
drwxrwxrwx       2 vantive    dba           2048 Apr 26 11:38 data/
drwxrwxrwx       2 vantive    dba           4096 Apr 26 11:46 log/
drwxrwxr-x     8 vantive    dba             96 Aug  9  2001 movebinary/
drwxrwxr-x   3 vantive    dba             96 Apr 26 11:32 omudata/
drwxrwxr-x   2 vantive    dba           2048 Aug  9  2001 views/
arvant02:/opt/vantive8>

The above alias lists those directories belonging to the subdirectory omu.
I hardcoded the "omu" directory into the dir alias script.

If,however, I want to replace the hardcoded "omu" subdirectory value with a
variable that I pass in as a command line argument to the alias command
"dir", such as, dir sub_dir <enter>, how would I alter the alias script to
enable this?

Mark

 
 
 

How can I pass a command line argument to an aliased command?

Post by Bruce Burhan » Sat, 21 Sep 2002 05:49:08



Quote:> How can I pass a command line argument to an aliased command?

> In this example, I want to pass a candidate directory name as a command
line
> argument and have it processed by the "dir" alias script.

> For example:

> arvant02:/opt/vantive8> alias dir='ll -F omu | egrep ^d '
> arvant02:/opt/vantive8> dir
> drwxrwxr-x       2 vantive    dba           2048 Aug  9  2001 apps_ora8/
> drwxrwxrwx       2 vantive    dba           2048 Apr 26 11:46 backup/
> drwxrwxrwx       2 oracle     dba             96 Oct  9  2001 core_22352/
> drwxrwxrwx       2 vantive    dba           2048 Apr 26 11:38 data/
> drwxrwxrwx       2 vantive    dba           4096 Apr 26 11:46 log/
> drwxrwxr-x     8 vantive    dba             96 Aug  9  2001 movebinary/
> drwxrwxr-x   3 vantive    dba             96 Apr 26 11:32 omudata/
> drwxrwxr-x   2 vantive    dba           2048 Aug  9  2001 views/
> arvant02:/opt/vantive8>

> The above alias lists those directories belonging to the subdirectory omu.
> I hardcoded the "omu" directory into the dir alias script.

> If,however, I want to replace the hardcoded "omu" subdirectory value with
a
> variable that I pass in as a command line argument to the alias command
> "dir", such as, dir sub_dir <enter>, how would I alter the alias script to
> enable this?

> Mark

        Any reason you can't write a function instead?

I'm using bash2.....

 rid  ( )

{

    ll -F  "$1"  | egrep ^d ;

Quote:}

    Just write it in your  startup file   and  enter the directory you want
as arg 1 to  rid.

Bruce<+>