in reply to Getting the shell's version of working directory, without PWD's help

> I want absolute path but with symbolic links not resolved.

I'm not sure what exactly your asking for???

Dependent on interpretation you might wanna try

HTH

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Update

cwd() does - like documented - the same like `pwd`

$ mkdir dir $ ln -s dir sym $ cd sym $ pwd /data/data/com.termux/files/home/sym $ perl -MCwd -E'say cwd()' /data/data/com.termux/files/home/sym ### update2: note the difference $ perl -MCwd -E'say getcwd()' /data/data/com.termux/files/home/dir

Replies are listed 'Best First'.
Re^2: Getting the absolute path of a script, without PWD (update)
by perlancar (Hermit) on Jul 15, 2021 at 12:05 UTC
    Yup sorry, bad title. It's not the absolute path of the script I want, but the "current directory" in absolute path format. By the way, $0 and __FILE__ also do not seem to resolve symlinks so I'm guessing perl gets them from the shell also.
      You've replied to my update without reading it.

      getcwd and cwd are different and it's clearly documented

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I've tested both cwd() and getcwd() before, and looked at the source. They both resolve symlinks. And the pwd and PWD variable from bash are not the same.

        UPDATE:Okay, so when we type pwd in bash by default we get the shell builtin, not the external Unix utility (/bin/pwd on my system). And the shell's pwd defaults to -L (logical) and we get the bash PWD. The external Unix utility defaults to -P (physical) which resolves symlinks. And if we run /bin/pwd -L, it still retrieves from PWD environment variable. Confirming my original question, we do need PWD and there's no way in Perl we can get the same version without PWD.