Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by perlancar (Hermit)
on Jul 16, 2021 at 07:51 UTC ( [id://11135058]=note: print w/replies, xml ) Need Help??


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 (Cardinal) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-25 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found