Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, whenever you cd, OLDPWD gets set to the directory you just changed from. cd will substitute $OLDPWD when you cd to "-". Perhaps even less well know, the shell itself will expand ~- to $OLDPWD so if you ever want to see where cd - would take you, or just list the files from your previous working directory you could do "echo ~-" or "ls ~-" respectively.


PWD, OLDPWD, and cd - are POSIX

~- is a bashism You can add a number to navigate the pushd/popd/dirs stack https://www.gnu.org/software/bash/manual/bashref.html#Tilde-...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: