Jim Meyering <[EMAIL PROTECTED]> writes:

> For true, Peter Seebach made the point back in 1999[*] that one should
> be able to use true-with-any-arguments as a no-op.  Sure, it's usually
> better to use `:', but sometimes we need a command that can be `exec'd.

That's reasonable, but the current usage is so awkward that I wonder
whether anybody'd want to do it.  As I understand it, if you want to
exec a 'true-with-any-arguments' command, you need something like this:

     setenv ("POSIXLY_CORRECT", "", 1);
     execlp ("true", "true", arg1, ..., argn, (char *) 0);

But that's tricky, and it's not portable code in general, as POSIX
doesn't promise that "true" does nothing if you pass it arguments.
How about recommending this instead?

     execlp ("sh", "sh", "-c", ":", arg1, ..., argn, (char *) 0);

This is shorter and simpler, and POSIX says it's portable.

> I do admit that the name POSIXLY_CORRECT is at best misleading in these
> cases, now that I see the behavior it disables is permitted by POSIX.

If the above argument hasn't convinced you, and you still prefer
having "true" behave differently based on some environment variable,
how about using a different environment variable, e.g.,
IGNORE_HELP_AND_VERSION?  That would remove the misleading bit.....
But now that I write this, I think I am going off the deep end.  Let's
just have "true" either always ignore "--help" and "--version", or
always obey them.  I don't much care which, but I think an environment
var is overkill here.


> As for `yes', shouldn't there be a way to make it print `--h', `--help'
> or `--version' repeatedly?

Sure, but that should be "yes -- --help".  Hmm, I see this isn't
working correctly now, and there are a few other commands that
mishandle "--" (including chroot, hostid, hostname).  Here's a patch
to fix this.  (My CVS doesn't have any changes to NEWS and
doc/coreutils.texi so this patch includes the same fixes as before for
those, along with new changes for the "--" stuff.)

2004-06-15  Paul Eggert  <[EMAIL PROTECTED]>

        * NEWS: Remove special cases for POSIXLY_CORRECT when POSIX allows
        the GNU behavior.  "--" is now supported by chroot, hostid, hosname,
        pwd, sync, yes.
        * doc/coreutils.texi (pr invocation, unlink invocation, false
        invocation, true invocation): Document this.
        * src/chroot.c (main): Handle "--".
        * src/hostid.c (main): Likewise.
        * src/hostname.c (main): Likewise.
        * src/pwd.c (main): Likewise.
        * src/sync.c (main): Likewise.
        * src/yes.c (main): Likewise.
        * src/true.c (main): Recognize --help and --version even if
        POSIXLY_CORRECT is set.
        * src/yes.c (main): Likewise.

Index: NEWS
===================================================================
RCS file: /home/meyering/coreutils/cu/NEWS,v
retrieving revision 1.214
diff -p -u -r1.214 NEWS
--- NEWS        8 Jun 2004 13:23:42 -0000       1.214
+++ NEWS        15 Jun 2004 20:36:53 -0000
@@ -117,6 +117,17 @@ GNU coreutils NEWS                      
   echo -e '\xHH' now outputs a byte whose hexadecimal value is HH,
   for compatibility with bash.
 
+  In the following cases POSIX allows the default GNU behavior,
+  so when POSIXLY_CORRECT is set:
+
+    false, printf, true, unlink, and yes all support --help and --option.
+    ls supports TABSIZE.
+    pr no longer depends on LC_TIME for the date format in non-POSIX locales.
+    printf supports \u, \U, \x.
+    tail supports two or more files when using the obsolete option syntax.
+
+  The usual `--' operand is now supported by chroot, hostid, hostname,
+  pwd, sync, and yes.
 
 * Major changes in release 5.2.1 (2004-03-12) [stable]
 
Index: doc/coreutils.texi
===================================================================
RCS file: /home/meyering/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.187
diff -p -u -r1.187 coreutils.texi
--- doc/coreutils.texi  7 Jun 2004 08:21:07 -0000       1.187
+++ doc/coreutils.texi  15 Jun 2004 20:12:17 -0000
@@ -1952,10 +1952,11 @@ e.g., @option{--date-format="Monday morn
 
 @vindex POSIXLY_CORRECT
 @vindex LC_TIME
-If the @env{POSIXLY_CORRECT} environment variable is not set, the date
+Normally the date
 format defaults to @samp{%Y-%m-%d %H:%M} (for example, @samp{2001-12-04
-23:59}); otherwise, the format depends on the @env{LC_TIME} locale
-category, with the default being @samp{%b %e %H:%M %Y} (for example,
+23:59}); but if the @env{POSIXLY_CORRECT} environment variable is set
+and the @env{LC_TIME} locale category specifies the @acronym{POSIX}
+locale, the default is @samp{%b %e %H:%M %Y} (for example,
 @samp{Dec@ @ 4 23:59 2001}.
 
 @item [EMAIL PROTECTED]@var{in-tabwidth}]]
@@ -7768,12 +7769,9 @@ On some systems @code{unlink} can be use
 directory.  On others, it can be used that way only by a privileged user.
 In the GNU system @code{unlink} can never delete the name of a directory.
 
[EMAIL PROTECTED] POSIXLY_CORRECT
-By default, @command{unlink} honors the @option{--help} and @option{--version}
-options.  That makes it a little harder to remove files named
[EMAIL PROTECTED] and @option{--version}, so when the environment variable
[EMAIL PROTECTED] is set, @command{unlink} treats such a command line
-arguments not as an option, but as an operand.
+The @command{unlink} command honors the @option{--help} and
[EMAIL PROTECTED] options.  To remove a file whose name begins with
[EMAIL PROTECTED], prefix the name with @samp{./}, e.g., @samp{unlink ./--help}.
 
 @exitstatus
 
@@ -9071,6 +9069,8 @@ given, it prints @samp{y} followed by a 
 Upon a write error, @command{yes} exits with status @samp{1}.
 
 The only options are a lone @option{--help} or @option{--version}.
+To output an argument that begins with
[EMAIL PROTECTED], precede it with @option{--}, e.g., @samp{yes -- --help}.
 @xref{Common options}.
 
 
@@ -9106,11 +9106,7 @@ pipeline.
 @dfn{failure}.  It can be used as a place holder in shell scripts
 where an unsuccessful command is needed.
 
[EMAIL PROTECTED] POSIXLY_CORRECT
-By default, @command{false} honors the @option{--help} and @option{--version}
-options.  However, that is contrary to @acronym{POSIX}, so when the environment
-variable @env{POSIXLY_CORRECT} is set, @command{false} ignores @emph{all}
-command line arguments, including @option{--help} and @option{--version}.
[EMAIL PROTECTED] honors the @option{--help} and @option{--version} options.
 
 This version of @command{false} is implemented as a C program, and is thus
 more secure and faster than a shell script implementation, and may safely
@@ -9138,11 +9134,7 @@ In most modern shells, @command{true} is
 you use @samp{true} in a script, you're probably using the built-in
 command, not the one documented here.
 
[EMAIL PROTECTED] POSIXLY_CORRECT
-By default, @command{true} honors the @option{--help} and @option{--version}
-options.  However, that is contrary to @acronym{POSIX}, so when the environment
-variable @env{POSIXLY_CORRECT} is set, @command{true} ignores @emph{all}
-command line arguments, including @option{--help} and @option{--version}.
[EMAIL PROTECTED] honors the @option{--help} and @option{--version} options.
 
 Note, however, that it is possible to cause @command{true}
 to exit with nonzero status: when invoked in [EMAIL PROTECTED] mode,
Index: src/chroot.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/chroot.c,v
retrieving revision 1.41
diff -p -u -r1.41 chroot.c
--- src/chroot.c        21 Jan 2004 22:47:09 -0000      1.41
+++ src/chroot.c        15 Jun 2004 20:35:53 -0000
@@ -75,6 +75,15 @@ main (int argc, char **argv)
 
   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
+
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
+
   if (argc <= 1)
     {
       error (0, 0, _("too few arguments"));
Index: src/hostid.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/hostid.c,v
retrieving revision 1.25
diff -p -u -r1.25 hostid.c
--- src/hostid.c        21 Jan 2004 23:08:09 -0000      1.25
+++ src/hostid.c        15 Jun 2004 20:36:05 -0000
@@ -73,6 +73,14 @@ main (int argc, char **argv)
   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
 
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
+
   if (argc > 1)
     {
       error (0, 0, _("too many arguments"));
Index: src/hostname.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/hostname.c,v
retrieving revision 1.50
diff -p -u -r1.50 hostname.c
--- src/hostname.c      29 Mar 2004 07:30:09 -0000      1.50
+++ src/hostname.c      15 Jun 2004 20:36:18 -0000
@@ -97,6 +97,14 @@ main (int argc, char **argv)
   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
 
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
+
 #ifdef HAVE_SETHOSTNAME
   if (argc == 2)
     {
Index: src/pwd.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/pwd.c,v
retrieving revision 1.46
diff -p -u -r1.46 pwd.c
--- src/pwd.c   20 Apr 2004 09:34:43 -0000      1.46
+++ src/pwd.c   15 Jun 2004 20:36:24 -0000
@@ -306,6 +306,14 @@ main (int argc, char **argv)
   parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
 
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
+
   if (1 < argc)
     error (0, 0, _("ignoring non-option arguments"));
 
Index: src/sync.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/sync.c,v
retrieving revision 1.46
diff -p -u -r1.46 sync.c
--- src/sync.c  21 Jan 2004 23:45:53 -0000      1.46
+++ src/sync.c  15 Jun 2004 20:36:53 -0000
@@ -67,6 +67,14 @@ main (int argc, char **argv)
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION,
                      usage, AUTHORS, (char const *) NULL);
 
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
+
   if (1 < argc)
     error (0, 0, _("ignoring all arguments"));
 
Index: src/true.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/true.c,v
retrieving revision 1.19
diff -p -u -r1.19 true.c
--- src/true.c  5 Nov 2003 03:43:30 -0000       1.19
+++ src/true.c  9 Jun 2004 19:22:50 -0000
@@ -56,8 +56,8 @@ main (int argc, char **argv)
   atexit (close_stdout);
 
   /* Recognize --help or --version only if it's the only command-line
-     argument and if POSIXLY_CORRECT is not set.  */
-  if (argc == 2 && getenv ("POSIXLY_CORRECT") == NULL)
+     argument.  */
+  if (argc == 2)
     {
       if (STREQ (argv[1], "--help"))
        usage (EXIT_SUCCESS);
Index: src/yes.c
===================================================================
RCS file: /home/meyering/coreutils/cu/src/yes.c,v
retrieving revision 1.53
diff -p -u -r1.53 yes.c
--- src/yes.c   21 Jan 2004 23:50:38 -0000      1.53
+++ src/yes.c   15 Jun 2004 20:36:48 -0000
@@ -71,10 +71,16 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  /* Don't recognize --help or --version if POSIXLY_CORRECT is set.  */
-  if (getenv ("POSIXLY_CORRECT") == NULL)
-    parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
-                       usage, AUTHORS, (char const *) NULL);
+  parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION,
+                     usage, AUTHORS, (char const *) NULL);
+
+  /* The above handles --help and --version.
+     Since there is no other invocation of getopt, handle `--' here.  */
+  if (1 < argc && STREQ (argv[1], "--"))
+    {
+      --argc;
+      ++argv;
+    }
 
   if (argc == 1)
     {


_______________________________________________
Bug-coreutils mailing list
[EMAIL PROTECTED]
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to