Im confused about this bash option:


If set, do not resolve symbolic links when performing commands such as cd which change the current directory. The physical directory is used instead. By default, Bash follows the logical chain of directories when performing commands which change the current directory.

For example, if /usr/sys is a symbolic link to /usr/local/sys then:

$ cd /usr/sys; echo $PWD
$ cd ..; pwd

If set -P is on, then:

$ cd /usr/sys; echo $PWD
$ cd ..; pwd

I thought resolve means to follow? e.g /usr/sys points at /usr/local/sys, so it would get resolved to /usr/local/sys. But the example above says that when set -P is on, /usr/sys becomes /usr/local/says? Even though it says if its on it shouldnt resolve symbolic links

  • The question is: who is doing the resolving? With the default behaviour, bash resolves the symlink and then pretends that you're in /usr/sys instead of in /usr/local/sys. With set -P, bash doesn't do anything by itself and lets the underlying system behaviour show (which is also to resolve the symlink, but now it's impossible to be in /usr/sys).
    – muru
    Feb 28 at 2:58

1 Answer 1

vm1:/home/millerp > ln -s /var/log ./log
vm1:/home/millerp > set -P
vm1:/home/millerp > cd log
vm1:/var/log > cd
vm1:/home/millerp > set +P
vm1:/home/millerp > cd log
vm1:/home/millerp/log >

With -P, the cwd is not resolved (converted) to the link, it is shown as the actual (physical) path. With +P, the cwd is resolved to the symlink path.

As muru points out, the question is 'resovlved for whom?'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.