bug#12964: [PATCH] printenv: -n option added -- show names of variables.

2018-10-10 Thread Bernhard Voelker
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





bug#12964: [PATCH] printenv: -n option added -- show names of variables.

2018-10-09 Thread Assaf Gordon

(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





bug#12964: [PATCH] printenv: -n option added -- show names of variables.

2012-11-22 Thread Van de Bugger
From 50aefa315b50b151a2192168fa46e9a311c06147 Mon Sep 17 00:00:00 2001
From: Van de Bugger van.de.bug...@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, --namesprint 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