Given
zsh
5+setopt chase_links
PWD
has not been set abnormally Is
[[ "$PWD" == "${${:-.}:A}" ]]
Always true?
No, this is not always true:
xvii:~> ls -l foo
lrwxrwxrwx 1 vinc17 vinc17 10 2014-07-05 01:12:06 foo -> bar/subdir/
xvii:~> bash
vinc17@xvii:~$ cd foo
vinc17@xvii:~/foo$ pwd
/home/vinc17/foo
vinc17@xvii:~/foo$ zsh -f
xvii% echo $PWD
/home/vinc17/foo
xvii% setopt chase_links
xvii% echo $PWD
/home/vinc17/foo
xvii% echo "${${:-.}:A}"
/home/vinc17/bar/subdir
xvii% pwd
/home/vinc17/bar/subdir
But if zsh is started in a current working directory that has no symlink segments, then the current working directory will never have symlink segments either after a cd
(or equivalent), and ..
or .
in the current working directory are not possible either since they are resolved when changing the directory, so that $PWD
and ${${:-.}:A}
should be equivalent if the directory still exists (see below).
In the above example, after a cd .
, zsh updates $PWD
to /home/vinc17/bar/subdir
. However, a cd .
doesn't make both forms equivalent in all cases:
xvii% mkdir my_dir
xvii% cd my_dir
xvii% rmdir ../my_dir
xvii% echo $PWD
/home/vinc17/my_dir
xvii% echo "${${:-.}:A}"
/home/vinc17/my_dir
xvii% pwd
/home/vinc17/my_dir
xvii% cd .
xvii% echo $PWD
/home/vinc17/my_dir
xvii% echo "${${:-.}:A}"
xvii% pwd
.
xvii% echo "$(realpath .)"
.: No such file or directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With