On 06/30/2014 03:40 AM, Jim Meyering wrote:
> On Sun, Jun 29, 2014 at 9:42 AM, Pádraig Brady <[email protected]> wrote:
>> POSIX says that `pwd` without options should assume -L is specified.
>> pwd is most often invoked as a shell builtin and bash, dash, zsh, ksh
>> all follow POSIX and assume that -L is the default.
>> However coreutils pwd assumes -P is the default, according to this
>> comment in the source:
>>
>>   "POSIX requires a default of -L, but most scripts expect -P."
>>
>> I'm not sure that is correct though, since the vast majority
>> of scripts would be executing the shell builtin?
>>
>> Note also that the solaris sh builtin and separate pwd util
>> only support -P behavior.
> 
> Hi Pádraig,
> 
> When I wrote the original pwd.c, the standard was
> POSIX 1003.2-1992, and someone had actually sent
> me hard copy for Volumes 1 and 2. I've just checked (still have them)
> and see it says simply to print "an absolute pathname of the current
> working directory", so I made it call xgetcwd and print that.
> 
> I think it's fine to make -L the default, now.  As you say, it will make
> our version conform to the newer standard and eliminate a small
> source of incompatibility between the modern built-ins and exec'd
> versions of this command. Any time we make such a change, there
> is a risk of causing a script to malfunction, but I think very few scripts
> exec pwd, and fewer still would malfunction with this change.
> 
> I like the idea.

Thanks for the detail.

What got me thinking about this was a query about
realpath -sL currently not using $PWD for relative arguments.
Details at: https://bugzilla.redhat.com/1114225#1
It might be useful to change that, though I'm less sure about that one.

I'll push the attached for the pwd change later.

thanks,
Pádraig.
>From 3e89d5bb9b34861c17cd23f5efd8323eec4f0bab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 30 Jun 2014 10:15:26 +0100
Subject: [PATCH] pwd: assume -L mode by default, as per POSIX

* src/pwd.c (main): Adjust default mode to be "logical"
and independent of the POSIXLY_CORRECT env var.
(usage): Mention the default mode of operation.
* doc/coreutils.texi (pwd invocation): Adjust accordingly.
* tests/misc/pwd-option.sh: Likewise.
* NEWS: Mention the change in behavior.
---
 NEWS                     |    3 +++
 doc/coreutils.texi       |    3 +--
 src/pwd.c                |    7 +++++--
 tests/misc/pwd-option.sh |    5 +----
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 4e90b79..a72d3bd 100644
--- a/NEWS
+++ b/NEWS
@@ -117,6 +117,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   will now honor an empty or unknown TERM environment variable,
   and not output colors even with --colors=always.
 
+  pwd now conforms to POSIX and common practice with shell builtins
+  to assume -L by default, outputting $PWD from the environment if appropriate.
+
 ** Improvements
 
   chroot has better --userspec and --group look-ups, with numeric IDs never
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 96220c3..d0c8ea8d 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -13738,8 +13738,7 @@ will be symbolic links.
 @cindex symbolic links and @command{pwd}
 If @option{-L} and @option{-P} are both given, the last one takes
 precedence.  If neither option is given, then this implementation uses
-@option{-P} as the default unless the @env{POSIXLY_CORRECT}
-environment variable is set.
+@option{-L} as the default.
 
 @mayConflictWithShellBuiltIn{pwd}
 
diff --git a/src/pwd.c b/src/pwd.c
index 4993dfb..af9ef50 100644
--- a/src/pwd.c
+++ b/src/pwd.c
@@ -64,6 +64,9 @@ Print the full filename of the current working directory.\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
+      fputs (_("\n\
+If no option is specified, -L is assumed.\n\
+"), stdout);
       printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
       emit_ancillary_info ();
     }
@@ -324,8 +327,8 @@ int
 main (int argc, char **argv)
 {
   char *wd;
-  /* POSIX requires a default of -L, but most scripts expect -P.  */
-  bool logical = (getenv ("POSIXLY_CORRECT") != NULL);
+  /* POSIX requires a default of -L.  */
+  bool logical = true;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
diff --git a/tests/misc/pwd-option.sh b/tests/misc/pwd-option.sh
index afb9487..983726b 100755
--- a/tests/misc/pwd-option.sh
+++ b/tests/misc/pwd-option.sh
@@ -40,11 +40,8 @@ printf %s\\n "$base/a/b" >> exp || fail=1
 env -- pwd --physical >> out || fail=1
 printf %s\\n "$base/a/b" >> exp || fail=1
 
-# By default, we use -P unless POSIXLY_CORRECT.
+# By default, we use -L like POSIX and various shells.
 env -- pwd >> out || fail=1
-printf %s\\n "$base/a/b" >> exp || fail=1
-
-env -- POSIXLY_CORRECT=1 pwd >> out || fail=1
 printf %s\\n "$base/c" >> exp || fail=1
 
 # Make sure we reject bogus values, and silently fall back to -P.
-- 
1.7.7.6

Reply via email to