GNU bug report logs -
#34672
id: add "--numeric" option
Previous Next
To reply to this bug, email your comments to 34672 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#34672
; Package
coreutils
.
(Tue, 26 Feb 2019 20:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Giuseppe Scrivano <gscrivano <at> gnu.org>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Tue, 26 Feb 2019 20:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
there are cases where I'd like to see only the numeric values in the
`id` output.
I could get this information separately, but having a new option
and just one command simplifies the task.
Are you fine with a change like the following?
If you have nothing against it, I will clean it up and send it again.
Thanks,
Giuseppe
diff --git a/src/id.c b/src/id.c
index d710caaee..e16c9c625 100644
--- a/src/id.c
+++ b/src/id.c
@@ -59,6 +59,8 @@ static bool ok = true;
static bool multiple_users = false;
/* If true, output user/group name instead of ID number. -n */
static bool use_name = false;
+/* If true, prints only numbers for the IDs. */
+static bool just_numeric = false;
/* The real and effective IDs of the user to print. */
static uid_t ruid, euid;
@@ -78,6 +80,7 @@ static struct option const longopts[] =
{"group", no_argument, NULL, 'g'},
{"groups", no_argument, NULL, 'G'},
{"name", no_argument, NULL, 'n'},
+ {"numeric", no_argument, NULL, 'N'},
{"real", no_argument, NULL, 'r'},
{"user", no_argument, NULL, 'u'},
{"zero", no_argument, NULL, 'z'},
@@ -105,6 +108,7 @@ or (when USER omitted) for the current user.\n\
-g, --group print only the effective group ID\n\
-G, --groups print all group IDs\n\
-n, --name print a name instead of a number, for -ugG\n\
+ -N, --numeric print only numeric values for IDs\n\
-r, --real print the real ID instead of the effective ID, with -ugG\n\
-u, --user print only the effective user ID\n\
-z, --zero delimit entries with NUL characters, not whitespace;\n\
@@ -137,7 +141,7 @@ main (int argc, char **argv)
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "agnruzGZ", longopts, NULL)) != -1)
+ while ((optc = getopt_long (argc, argv, "agnruzGZN", longopts, NULL)) != -1)
{
switch (optc)
{
@@ -178,6 +182,9 @@ main (int argc, char **argv)
case 'G':
just_group_list = true;
break;
+ case 'N':
+ just_numeric = true;
+ break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
@@ -361,19 +368,19 @@ print_full_info (const char *username)
printf (_("uid=%s"), uidtostr (ruid));
pwd = getpwuid (ruid);
- if (pwd)
+ if (!just_numeric && pwd)
printf ("(%s)", pwd->pw_name);
printf (_(" gid=%s"), gidtostr (rgid));
grp = getgrgid (rgid);
- if (grp)
+ if (!just_numeric && grp)
printf ("(%s)", grp->gr_name);
if (euid != ruid)
{
printf (_(" euid=%s"), uidtostr (euid));
pwd = getpwuid (euid);
- if (pwd)
+ if (!just_numeric && pwd)
printf ("(%s)", pwd->pw_name);
}
@@ -381,7 +388,7 @@ print_full_info (const char *username)
{
printf (_(" egid=%s"), gidtostr (egid));
grp = getgrgid (egid);
- if (grp)
+ if (!just_numeric && grp)
printf ("(%s)", grp->gr_name);
}
@@ -413,9 +420,12 @@ print_full_info (const char *username)
if (i > 0)
putchar (',');
fputs (gidtostr (groups[i]), stdout);
- grp = getgrgid (groups[i]);
- if (grp)
- printf ("(%s)", grp->gr_name);
+ if (! just_numeric)
+ {
+ grp = getgrgid (groups[i]);
+ if (grp)
+ printf ("(%s)", grp->gr_name);
+ }
}
free (groups);
}
Regards,
Giuseppe
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#34672
; Package
coreutils
.
(Thu, 28 Feb 2019 07:24:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 34672 <at> debbugs.gnu.org (full text, mbox):
severity 34672 wishlist
tags 34672 notabug
stop
On 2/26/19 9:36 PM, Giuseppe Scrivano wrote:
> Hi,
>
> there are cases where I'd like to see only the numeric values in the
> `id` output.
>
> I could get this information separately, but having a new option
> and just one command simplifies the task.
>
> Are you fine with a change like the following?
>
> If you have nothing against it, I will clean it up and send it again.
>
> Thanks,
> Giuseppe
Thanks for the patch.
What is the use case? I mean, if one wants only the numeric numbers,
then this is usually in a script for automatic processing, and then
I thinks it's clearer to have uid and group/groups separated:
$ id -u
1000
$ id -g
100
$ id -G
100 454 457 480 492
There's even a -z option to separate by NULs instead of white space.
And, when still needing all in the same output, one could filter like e.g.:
$ id | sed 's/([^)]*)//g'
uid=1000 gid=100 groups=100,454,457,480,492
So I'm currently 40:60 to add it.
Thanks & have a nice day,
Berny
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#34672
; Package
coreutils
.
(Thu, 28 Feb 2019 10:01:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 34672 <at> debbugs.gnu.org (full text, mbox):
Hi Bernhard,
Bernhard Voelker <mail <at> bernhard-voelker.de> writes:
> Thanks for the patch.
>
> What is the use case? I mean, if one wants only the numeric numbers,
> then this is usually in a script for automatic processing, and then
> I thinks it's clearer to have uid and group/groups separated:
>
> $ id -u
> 1000
>
> $ id -g
> 100
>
> $ id -G
> 100 454 457 480 492
>
> There's even a -z option to separate by NULs instead of white space.
>
> And, when still needing all in the same output, one could filter like e.g.:
>
> $ id | sed 's/([^)]*)//g'
> uid=1000 gid=100 groups=100,454,457,480,492
>
> So I'm currently 40:60 to add it.
as I said, it doesn't really add anything. It is just an aesthetic
shortcut that I find useful when using Linux user namespaces. In that
use case the uid->username lookup doesn't make much sense.
Regards,
Giuseppe
Severity set to 'wishlist' from 'normal'
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 28 Mar 2019 18:36:02 GMT)
Full text and
rfc822 format available.
Added tag(s) notabug.
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 28 Mar 2019 18:36:02 GMT)
Full text and
rfc822 format available.
Changed bug title to 'id: add "--numeric" option' from '[RFC] id --numeric'
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Thu, 28 Mar 2019 18:36:02 GMT)
Full text and
rfc822 format available.
This bug report was last modified 6 years and 170 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.