How did not know that #bash/#zsh automatically keeps track of the $OLDPWD and even offers a shortcut `~-`?

`cd ~-`

https://www.johndcook.com/blog/2026/03/01/tilde-dash/

Shell variable ~-

After writing the previous post, I poked around in the bash shell documentation and found a handy feature I'd never seen before, the shortcut ~-. I frequently use the command cd - to return to the previous working directory, but didn't know about ~- as a shotrcut for the shell variable $OLDPWD which contains the

John D. Cook | Applied Mathematics Consulting