in reply to Re^4: Getting the absolute path of a script, without PWD (bug?)(update)
in thread Getting the shell's version of working directory, without PWD's help

after further investigation, it seems that `pwd` inside Perl doesn't default like pwd in bash ... which is unexpected

The answer is perhaps this in perlop for the qx//:

if the string contains no shell metacharacters then it will executed directly.

So although in general qx// uses the shell, if we say `pwd` then perl will execute /bin/pwd, which defaults to -P. If we say `bash -c pwd` then bash will execute its shell builtin version of pwd, which defaults to -L.

  • Comment on Re^5: Getting the absolute path of a script, without PWD (bug?)(update)

Replies are listed 'Best First'.
Re^6: Getting the absolute path of a script, without PWD (bug?)(update)
by choroba (Archbishop) on Jul 16, 2021 at 08:52 UTC
    > it seems that `pwd` inside Perl doesn't default like pwd in bash

    Note that qx// doesn't call bash but sh, which might be a different shell (/bin/dash on Ubuntu, for example).

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Noted, but that's not the cause of the difference here. `pwd` under dash still calls the shell builtin, which defaults to pwd -L.