Your shell's 'pwd' command is a built-in that doesn't resort to /bin/pwd unless it has to. Even if you get Perl to call the shell's pwd instead of /bin/pwd, the shell will have started up not knowing where it is and will have to resort to the same steps that /bin/pwd uses and so will report the (correct) directory that you don't want to see.

You see, the shell keeps track of 'cd' commands (it has to process these itself as a child process calling chdir won't change the current working directory of its parent process) and stores the perceived current working directory which it reports if you ask it for $PWD or run 'pwd'.

The best advice I've come up with is to have your Perl program check $ENV{PWD} and, if it is the same as "." (stat both of them and compare device number and inode number -- if you are on a Unixish enough file system), then you can use it instead of redetermining the current working directory any of the other ways.

                - tye

In reply to Re: `pwd`, sh, and the amd automounter (/bin/) by tye
in thread `pwd`, sh, and the amd automounter by preston

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.