How do I pass the command line arguments to an alias? Here is a sample:
alias mkcd='mkdir $1; cd $1;'
But in this case the $xx is getting translated at the alias creating time and not at runtime. I have, however, created a workaround using a shell function (after googling a little) like below:
function mkcd(){ mkdir $1 cd $1 }
Just wanted to know if there is a way to make aliases that accept CL parameters.
BTW - I use 'bash' as my default shell.
You actually can't do what you want with Bash aliases, since aliases are static. Instead, use the function you have created.
Look here for more information: http://www.mactips.org/archives/2008/01/01/increase-productivity-with-bash-aliases-and-functions/. (Yes I know it's mactips.org, but it's about Bash, so don't worry.)
To quote the bash man page:
So it looks like you've answered your own question -- use a function instead of an alias
This works in ksh:
The "-x" option make the alias "exported" - alias is visible in subshells.
And be aware of fact that aliases defined in a script are not visible in that script (because aliases are expanded when a script is loaded, not when a line is interpreted). This can be solved with executing another script file in same shell (using dot).
I found that functions cannot be written in ~/.cshrc file .. Here in alias which takes arguments
for example, arguments passed to 'find' command
where abc is the argument passed as !:1
I think you are able to do it with shell functions if you are using bash: http://www.cyberciti.biz/faq/linux-unix-pass-argument-to-alias-command/
function count(){ python -c "for num in xrange($1):print num";}