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/
$ cd 6 7
$ pwd
$ bash
$ cd 7 6
bash: cd: 7: No such file or directory
$ c() { cd ${PWD/$1/$2}; }
$ c 7 6
$ pwd

Categorized as linux, unix Tagged

By Laurent Schneider

Oracle Certified Master


  1. 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; }

  2. Pingback: cd OLD NEW | Oracle
  3. @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.

Leave a comment

Your email address will not be published.