Pass Command Line Arguments To a Bash Alias Command

How do I pass all command line args to my bash alias called foo. For example:

alias foo=”/path/to/command [email protected]

However [email protected] get interpreted when creating the alias instead of during the execution of the alias and escaping the $ doesn’t work either. How do I solve this problem?

You need to use shell function instead of an alias to get rid of this problem. You can define foo as follows:

function foo() { /path/to/command "[email protected]" ;}

function foo() { /path/to/command "[email protected]" ;}

OR

foo() { /path/to/command "[email protected]" ;}

foo() { /path/to/command "[email protected]" ;}

Finally, call your foo() using the following syntax:
foo arg1 arg2 argN
Make sure you add your foo() to ~/.bash_profile file.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.