GNU bug report logs -
#12964
[PATCH] printenv: -n option added -- show names of variables.
Previous Next
To reply to this bug, email your comments to 12964 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#12964
; Package
coreutils
.
(Fri, 23 Nov 2012 00:31:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Van de Bugger <van.de.bugger <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Fri, 23 Nov 2012 00:31:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From 50aefa315b50b151a2192168fa46e9a311c06147 Mon Sep 17 00:00:00 2001
From: Van de Bugger <van.de.bugger <at> gmail.com>
Date: Fri, 23 Nov 2012 02:38:48 +0400
Subject: [PATCH] printenv: -n option added -- show names of variables.
* src/printenv.c: -n option added -- show names of variables.
---
src/printenv.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/printenv.c b/src/printenv.c
index 5c01f8d..b4583bd 100644
--- a/src/printenv.c
+++ b/src/printenv.c
@@ -49,6 +49,7 @@ static struct option const longopts[] =
{"null", no_argument, NULL, '0'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
+ {"names", no_argument, NULL, 'n'},
{NULL, 0, NULL, 0}
};
@@ -69,6 +70,9 @@ If no VARIABLE is specified, print name and value
pairs for them all.\n\
fputs (_("\
-0, --null end each output line with 0 byte rather than newline\n
\
"), stdout);
+ fputs (_("\
+ -n, --names print also names of the specified environment
VARIABLE(s)\n\
+"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
@@ -81,11 +85,12 @@ int
main (int argc, char **argv)
{
char **env;
- char *ep, *ap;
+ char *ep, *ap, *bp;
int i;
bool ok;
int optc;
bool opt_nul_terminate_output = false;
+ bool opt_show_names = false;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -96,13 +101,16 @@ main (int argc, char **argv)
initialize_exit_failure (PRINTENV_FAILURE);
atexit (close_stdout);
- while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) !=
-1)
+ while ((optc = getopt_long (argc, argv, "+iu:0n", longopts, NULL)) !=
-1)
{
switch (optc)
{
case '0':
opt_nul_terminate_output = true;
break;
+ case 'n':
+ opt_show_names = true;
+ break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
@@ -130,13 +138,14 @@ main (int argc, char **argv)
for (env = environ; *env; ++env)
{
- ep = *env;
+ bp = ep = *env;
ap = argv[i];
while (*ep != '\0' && *ap != '\0' && *ep++ == *ap++)
{
if (*ep == '=' && *ap == '\0')
{
- printf ("%s%c", ep + 1,
+ printf ("%s%c",
+ opt_show_names ? bp : ep + 1,
opt_nul_terminate_output ? '\0' : '\n');
matched = true;
break;
--
1.7.11.7
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#12964
; Package
coreutils
.
(Tue, 09 Oct 2018 21:34:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 12964 <at> debbugs.gnu.org (full text, mbox):
(Triaging old bugs)
Hello,
On 22/11/12 03:42 PM, Van de Bugger wrote:
> Subject: [PATCH] printenv: -n option added -- show names of variables.
>
> * src/printenv.c: -n option added -- show names of variables.
> ---
> src/printenv.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
Thank you for the patch. It seem it have slipped between the cracks long
ago - sorry about that.
So summarize:
With your patch, using "printenv -n VARNAME" adds
the variable name to the output. e.g.:
$ printenv HOME
/home/gordon
$ printenv -n HOME
HOME=/home/gordon
From a cursory look this seems like a non-standard extension
that is not available in any other 'printenv' implementations.
Do you have any specific use-cases for this functionality
(that can't be easily done with existing methods) ?
I'm inclined to close it as "wontfix" - but will wait few days
in case others want to chime in with other opinions.
regards,
- assaf
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#12964
; Package
coreutils
.
(Wed, 10 Oct 2018 09:04:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 12964 <at> debbugs.gnu.org (full text, mbox):
On 10/9/18 11:33 PM, Assaf Gordon wrote:
> With your patch, using "printenv -n VARNAME" adds
> the variable name to the output. e.g.:
>
> $ printenv HOME
> /home/gordon
>
> $ printenv -n HOME
> HOME=/home/gordon
>
> From a cursory look this seems like a non-standard extension
> that is not available in any other 'printenv' implementations.
This feature looks like it should be possible to write out the current settings
to a file which could later be sourced in:
printenv -n VAR > file
and in another shell (to get VAR back):
. file
I'm afraid this is problematic once the value of a variable starts to have
funny characters, even a simple blank ' ' already screws things up.
For this kind of save/restore, -n would need to do correct shell quoting.
Have a nice day,
Berny
Severity set to 'wishlist' from 'normal'
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Fri, 19 Oct 2018 01:17:01 GMT)
Full text and
rfc822 format available.
This bug report was last modified 6 years and 240 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.