Search code examples
bashcd

Behavior of 'cd --' (two hyphens)


I know that cd ~- changes directory to $OLDPWD.

cd -- appears to have the same behavior as cd ~-. Why?

I'm using "GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0)" on a Macbook.


Solution

  • That's not correct. cd -- changes to your home directory, just like cd only. Consider cd -- a pure cd with no options and no parameters given. See also https://unix.stackexchange.com/a/11382.