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.
In reply to Re: `pwd`, sh, and the amd automounter (/bin/)
by tye
in thread `pwd`, sh, and the amd automounter
by preston
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |