According to the Bash manual page the -e
option of cd
leads to an unsuccessful return status after a successful directory change.
If the -e option is supplied with -P and the current working directory cannot be successfully determined after a successful directory change, cd will return an unsuccessful status.
$ cd
$ mkdir -p test/a/b
$ cd test/a/b
$ rmdir ../b ../../a
$ cd -Pe ..; echo $?
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
1
Why is the above returning 1
? How could cd -Pe ..
possibly have made a successful directory change if the current as well as the parent directories do not exist anymore?
Also, if I want cd
to return an unsuccessful return status each and every time it cannot change to the desired directory, what are the situations where I have to add -Pe
? From what I understand it is only necessary if .
or ..
are used in the argument for cd
.