0

Im confused about this bash option:

-P

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
/usr/sys
$ cd ..; pwd
/usr

If set -P is on, then:

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

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

1
  • 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
    Commented Feb 28, 2023 at 2:58

1 Answer 1

0
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?'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .