Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by LanX (Sage)
on Jul 16, 2021 at 07:50 UTC ( #11135057=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

> The question is why is bash's pwd defaulting differently inside Perl?

From qx

Similarly to system, if the string contains no shell metacharacters then it will executed directly.

Not sure what is included into "shell metacharacters" but a simple semicolon seems to suffice to force execution via the shell ...

lanx@ubuntu14-large:/tmp/sym$ perl -MCwd -E'say `pwd;` ' /tmp/sym lanx@ubuntu14-large:/tmp/sym$ perl -MCwd -E'say `pwd` ' /tmp/dir lanx@ubuntu14-large:/tmp/sym$

update

simplified code

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

Replies are listed 'Best First'.
Re^6: Getting the absolute path of a script, without PWD (bug)
by perlancar (Hermit) on Jul 16, 2021 at 07:52 UTC
    You're 1 minute faster :-)
      Please, you should really file a bugreport against Cwd.

      Maybe they can't fix cwd() b/c of backwards compatibility but should at least clarify the documentation.

      From my POV it's already silly to call two different routines getcwd() and cwd()

      So you could suggest to add a new pwd() which always does something like `pwd -L`

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

        Maybe after I'm more knowledgeable about the actual differences between getcwd() and cwd(). Right now, it's not clear that cwd() should be "fixed". getcwd() tries to call getcwd(3) or reimplements it, while cwd() makes no such promise. And this statement is not strictly wrong: "For most systems it is identical to `pwd` (but without the trailing line terminator)." Though it might benefit the reader to be aware of the difference between pwd -P and pwd -L, and which one the reader is getting with `pwd`.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-09-19 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?