On 07/02/2014 12:23 AM, Bob Proulx wrote:
> It is also the exact opposite of very long standing traditional
> behavior.  And as Pádraig noted different from some other venerable
> systems such as Solaris and I will also note HP-UX too.  Is there any
> legacy Unix where /bin/pwd returns the logical path?  What does *BSD
> do?

FreeBSD man page states pwd defaults to -P

> For me now it is just something I tend to do from the keyboard.  In my
> own bash environment I set "set -o physical" so I never have to be
> concerned about it.  But when using someone else's environment if I
> type in pwd and know that it is lying to me then I routinely type in
> /bin/pwd in order to get the real path.  I know that I could type in
> "pwd -P" now too.  But my fingers know /bin/pwd.  I can't believe I am
> the only one who does this.

OK you've convinced me.
It seems all /bin/pwd default to -P
while all builtin pwd default to -L

POSIX should probably say something about that.

The attached reverts this change.

thanks,
Pádraig.
>From 6fb37b1e9aa924e7a556bc97606532e6cec4d1ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Wed, 2 Jul 2014 11:28:05 +0100
Subject: [PATCH] pwd: revert default mode back to -P

Revert commit v8.22-131-g3e89d5b as even though POSIX
states that the default mode should be -L,
common practice for stand-alone pwd implementations
is to default to -P.

* src/pwd.c (usage): Retain mention of the default mode of operation.
---
 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 a72d3bd..4e90b79 100644
--- a/NEWS
+++ b/NEWS
@@ -117,9 +117,6 @@ 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 d0c8ea8d..96220c3 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -13738,7 +13738,8 @@ 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{-L} as the default.
+@option{-P} as the default unless the @env{POSIXLY_CORRECT}
+environment variable is set.
 
 @mayConflictWithShellBuiltIn{pwd}
 
diff --git a/src/pwd.c b/src/pwd.c
index af9ef50..dabc98b 100644
--- a/src/pwd.c
+++ b/src/pwd.c
@@ -65,7 +65,7 @@ Print the full filename of the current working directory.\n\
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
       fputs (_("\n\
-If no option is specified, -L is assumed.\n\
+If no option is specified, -P is assumed.\n\
 "), stdout);
       printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
       emit_ancillary_info ();
@@ -327,8 +327,9 @@ int
 main (int argc, char **argv)
 {
   char *wd;
-  /* POSIX requires a default of -L.  */
-  bool logical = true;
+  /* POSIX requires a default of -L, but most scripts expect -P.
+     Currently shells default to -L, while stand-alone pwd default to -P.  */
+  bool logical = (getenv ("POSIXLY_CORRECT") != NULL);
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
diff --git a/tests/misc/pwd-option.sh b/tests/misc/pwd-option.sh
index 9b4664d..0eba942 100755
--- a/tests/misc/pwd-option.sh
+++ b/tests/misc/pwd-option.sh
@@ -40,8 +40,11 @@ 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 -L like POSIX and various shells.
+# By default, we use -P unless POSIXLY_CORRECT.
 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