bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #24949] coreutils pwd not implementing latest POSIX features


From: James Youngman
Subject: Re: [bug #24949] coreutils pwd not implementing latest POSIX features
Date: Mon, 1 Dec 2008 10:33:47 +0000

On Mon, Dec 1, 2008 at 2:04 AM, Paul D. Smith <address@hidden> wrote:
>
> Follow-up Comment #2, bug #24949 (project coreutils):
>
> The problem is that without -P I can't invoke pwd from things like Perl
> portably.  If I use "my $pwd = `pwd`;" and it runs a shell and uses the shell
> builtin version of pwd, then I get the wrong thing (I explicitly want the
> "real" path; what POSIX defines "pwd -P" to return).
>
> But on the other hand, if I use "my $pwd = `pwd -P`;", which is what a
> correct POSIX-conforming script would do, and it runs coreutils pwd instead of
> a shell builtin, I get a syntax error.

If you can rely enough on the platform being POSIX-conforming for -P
to work, then why not just use Perl's POSIX module?   It seems to me
that that would be more portable still.

~$ cat  pwd.pl
#! /usr/bin/perl

use POSIX qw(getcwd);
print "1: " . POSIX::getcwd() . "\n";

my $pwd = `pwd`; chop($pwd);
print "2: " . $pwd . "\n";

my $pwd = `pwd -P 2>/dev/null || pwd`; chop($pwd);
print "3: " . $pwd . "\n";

~$ perl pwd.pl
1: /home/james
2: /home/james
3: /home/james


James.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]