Pass command line argument to bash alias command
Q. How do I pass all command line args to my alias called foo. For example:
alias foo="/path/to/command $@"
However $@ 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?
A. You need to use shell function instead of an alias to get rid of this problem. Define foo as follows:
function foo() { /path/to/command "$@" ;}
Now you can call foo():
foo arg1 arg2 argN
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- How do I use shell aliases under Linux?
- Clear all Linux / UNIX bash shell aliases
- How to turn on or off colors in bash
- Find out if shell command is aliased or not
- How do I force IDE CD-ROM drive detecting during the Linux installation?
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: alias_command, bash_shell_function, command_line_args, shell_function



Recent Comments
Today ~ 7 Comments
Today ~ 33 Comments
Today ~ 2 Comments
Today ~ 1 Comment
Today ~ 2 Comments