bash Functions

I set up a bunch of aliases in my ~/.profile a while back, stuff like this:

  • alias ex1="ssh ex1.example.com"
  • alias src="cd ~/Sites/src"

Since I use the command line interface to Subversion (I normally prefer a GUI, but for SVN I think the command line is actually faster), I’ve been navigating my source directories more and more often.

Tonight I learned about bash functions – which have now replaced almost all of my aliases.

  • ex () { ssh $1.example.com ; }
  • src () { cd ~/Sites/src/$1/trunk ; }

Now I can do stuff like this:

ex ex1

and it becomes:

ssh ex1.example.com

and:

src tasks

becomes:

cd ~/Sites/src/tasks/trunk

Probably 70% of you our there don’t care, and 28% already knew this, but for that remaining 2%… this should be gold. 🙂