An Easy Way to Generate Aliases in Bash

I was looking at this quick bash tip and found that there is a better way to create aliases, than what is mentioned in the article:

function z(){
   varName=$1
   cwd=`pwd`
   eval alias $varName=”cd\ $cwd”
}

so, its usage will then become, say, “z webd” which will take the current dir and assign an alias webd to cd to it. Instead of remembering g1, g2 etc., we can remember the aliases with meaningful names. What do you think?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s