Its always a special moment if you learn a new parameter of a command you use for ages. In this case its the
-P parameter of cd.
Imagine you have a path like
/some/path/which/is/pretty/long and you have
/some/path/which/is/pretty/foo.
Both are directories and you have a symlink from ~/bar to the long directory and want to access the foo directory.
Because I am lazy I tried
cd bar and then
cd ../foo and ran into:
cd: no such file or directory: ../foo
I really wondered about this because
.. should be always a hardlink.
As cd is a shell-builtin in most cases because changing the directory in a subshell would not have any effect I looked into
SUS and it turned out that there is a
command line switch in cd for this:
If the -P option is in effect, the cd utility shall perform actions equivalent to the chdir() function, called with curpath as the path argument. If these actions succeed, the PWD environment variable shall be set to an absolute pathname for the current working directory and shall not contain filename components that, in the context of pathname resolution, refer to a file of type symbolic link. If there is insufficient permission on the new directory, or on any parent of that directory, to determine the current working directory, the value of the PWD environment variable is unspecified. If the actions equivalent to chdir() fail for any reason, the cd utility shall display an appropriate error message and not alter the PWD environment variable. Whether the actions equivalent to chdir() succeed or fail, no further steps shall be taken.
BTW, the csh is not susv3 complaint here it will do what I expected first without using -P.