Friday, July 30, 2010

Alias with arguments (BASH,CSH)

A neat way to make your life abit easier in Linux/Unix is using aliases, but how do you use an alias with an argument?
Let's say you want make a special "change directory" (we will call it cdd) command that will also display your current position in the file system tree.

Bash uses $1,$2,$3..etc for passed arguments, so we will add a little function inside our .bashrc file that will accomplish this mission:


cdd () { cd ${1} ; echo $PWD ; }

In C shell thing are little bit different, this will achieve the same effect when put into .cshrc:

alias cdd 'cd \!*;echo $cwd;'

No comments: