On 2025-12-10 09:33, Jon Turney wrote:
On 09/12/2025 10:16, Corinna Vinschen wrote:
On Dec  6 11:56, Jon Turney wrote:
On 05/12/2025 19:41, Corinna Vinschen wrote:
+      fprintf (stderr, "Usage: %s [-] [group]\n",

Maybe '[-|-l]'?

The usage message is the same as used by the shadow-utils newgrp
on Linux.  It supports -l, but doesn't print it for some reason.

If you think we should do it better, I can change our usage output
and send a v2 patch, no worries.

I am ambivalent.

The most recent SUS text [1] actually redefines the behavior of '-' as "unspecified" so '-l' seems preferred.

(This seems to revolve around standardizing '-' to refer to stdin)

[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/newgrp.html

FYI had a look at:

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sh.html#tag_20_110_05

and it now says:

"OPERANDS

The following operands shall be supported:

-
A single <hyphen-minus> shall be treated as the first operand and then ignored. If both '-' and "--" are given as arguments, or if other operands precede the single <hyphen-minus>, the results are undefined."

and see below that about sh STDIN usage.

+           program_invocation_short_name);
+      return 1;
+    }
         new_child_env = true;
         --argc;
         ++argv;
@@ -165,8 +165,16 @@ main (int argc, const char **argv)
       }
     else
       {
-      gr = getgrnam (argv[1]);
-      if (!gr)
+      char *eptr;
+
+      if ((gr = getgrnam (argv[1])) != NULL)
+    /*valid*/;
+      else if (isdigit ((int) argv[1][0])
+           && (gid = strtoul (argv[1], &eptr, 10)) != ULONG_MAX
+           && *eptr == '\0'
+           && (gr = getgrgid (gid)) != NULL)

I spent a bit of time worrying how this handled edge cases like '' or '0',
but I think it's all good!

Thanks for checking!

No problem!



--
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                -- Antoine de Saint-Exupéry

Reply via email to