Tuesday, May 24, 2005

If you use a shell

I am sure many of you who use a shell like the bash shell or the korn shell or any other shell for that matter must be power users of it by now. I will probably blog on some fun shell techniques, like the one in this blog.

Korn shell comes with a variant of the "cd" command that very few people are aware of. It is very useful for people who tend to have symmetrical directory hierarchies

Lets assume that you are in a directory structure as shown below

(1) /home/user/programming/drivers/source/cxx

and want to change directories to

(2) /home/user/programming/user_mode/source/cxx

Well, in KSH you can say

"cd drivers user_mode" and it will change from (1) to (2). I love this feature and miss it in the BASH shell, so I wrote my own wrapper (that's why I love *NIX)

function cd
case $# in
1) builtin cd $1
return ;;
2) builtin cd ${PWD/$1/$2}
return ;;
*) builtin cd $*
return ;;


In fact this version is slightly different from the KSH one, can you spot the difference?

Let me know if you do, I will post your name(s) on this blog
Post a Comment