Something I like in ksh is to change from /my/old/directory/path to /my/new/directory/path by typing cd old new. This does not work in bash
So I had to find a workaround 😉
$ ksh
$ cd /app/oracle/product/11.1.0.6/database/rdbms/admin
$ cd 6 7
$ pwd
/app/oracle/product/11.1.0.7/database/rdbms/admin
$ bash
$ cd 7 6
bash: cd: 7: No such file or directory
$ c() { cd ${PWD/$1/$2}; }
$ c 7 6
$ pwd
/app/oracle/product/11.1.0.6/database/rdbms/admin
I’ve also missed this, and your post made me think a bit further… now try this:
cd() { if [ -n “$2” ]; then builtin cd ${PWD/$1/$2}; else builtin cd $1; fi; }
good… then you will also need to take care of the -L or -P parameters
but I admit I was too coward to alias cd
but still lazy enought to find something shorter (c) 😀
nice for trick to use “cd” on ksh 😉
But I use bash shell… perhaps I’ll play about ksh 😉
Very nice ! 🙂
Pingback: cd OLD NEW | Oracle
@Laurent Schneider do you ever use -L or -P? I didn’t even know these options existed! But even so… easy enough the cover them as well.
Check the bash manpage for the “builtin” option command… is recommended exactly when you alias cd and the like.
cd -L is the default, so no I do not use it. But use cd -P and pwd -P a lot…
for instance, with 3 params 🙂
$ cd /sbin
$ cd -P s /
$ pwd
/usr/bin