bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] {print,}env -0


From: Eric Blake
Subject: Re: [RFC] {print,}env -0
Date: Tue, 27 Oct 2009 20:02:07 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Jim Meyering on 10/27/2009 12:07 PM:
>>> Yes, now I'm in favor of this, too.
>> This patch implements the option; I'm still working on developing a test
>> (comparing binary output takes a bit more effort) before I will commit
>> anything, but thought I'd at least get the review started.
> ...
> 
>> diff --git a/tests/misc/printenv b/tests/misc/printenv
> ...
>> +prog="$abs_top_builddir/src/printenv"
> 
> I've been switching to the use of "env -- prog_name",
> rather than $abs_name_of_prog.

Done.

>>
>> +   -0
>> +   --null
>> +        When no program is specified, output environment information
>> +        separated by nul bytes rather than newlines.
> 
> I have mixed feelings about these comments.
> I certainly wouldn't add them when writing from scratch --
> that sort of info belongs in documentation, not in comments.
> If you add the new entry, please mention "terminated", not "separated",
> and spell it as "NUL", not "nul".
> 
> I've just checked the documentation, and see it provides no examples.
> So the five examples in env.c need to move to coreutils.texi.
> Fixing that is now on my list of 5-10-minute tasks ;-)
> but anyone else is welcome to do it, too.
> 
> Thanks!

I went ahead and added one more patch to my queue (shown below), then pushed.

Meanwhile, I just noticed the following unusual behavior:

$ env a=b=c printenv a=b
c
$ env a=b=c tcsh -c 'printenv a=b'
c

Part of me thinks this is a bug (a=b is an invalid environment name, so
this should either print nothing, or fail with an error message),
particularly since I just changed env -u a=b to give an error for the same
case; but another part of me says that since tcsh has the same behavior,
we might be gratuitously breaking things by changing how printenv.c deals
with this corner case.  Right now, I'm leaning 75-25 on changing
coreutils' behavior (treating a=b as an env-var name just seems wrong, and
tcsh is so painful to use in general that I could care less if we don't
match the behavior of the tcsh builtin); and if we do change behavior, I'm
leaning 60-40 on making printenv a=b be silent (with exit status 1, since
no value was printed) rather than issue an error (with exit status 2,
because the user passed bad arguments).  Other opinions?

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrnph8ACgkQ84KuGfSFAYCF2QCgwHelApF8vPo900mwwviGr0fe
4LgAn0CWKcmFLslaBHdc9xhrzgaMQ+lu
=vvQn
-----END PGP SIGNATURE-----
>From 089aced0e4ea68100f2f95831ba0c3178d6e00d5 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Tue, 27 Oct 2009 17:20:56 -0600
Subject: [PATCH] doc: turn env comments into documentation

* src/env.c: Convert introductory comments...
* doc/coreutils.texi (env invocation): ...into documentation.
Suggested by Jim Meyering.
---
 doc/coreutils.texi |   51 ++++++++++++++++++++++++++++++++++++++++
 src/env.c          |   66 ----------------------------------------------------
 2 files changed, 51 insertions(+), 66 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index c5f5135..9b9f73b 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -14442,6 +14442,57 @@ env invocation
 specifications, the resulting environment is printed.  This is like
 specifying the @command{printenv} program.

+For some examples, suppose the environment passed to @command{env}
+contains @samp{LOGNAME=rms}, @samp{EDITOR=emacs}, and
address@hidden:/gnubin:/hacks}:
+
address@hidden @bullet
+
address@hidden
+Output the current environment.
address@hidden
+$ env | LC_ALL=C sort
+EDITOR=emacs
+LOGNAME=rms
+PATH=.:/gnubin:/hacks
address@hidden example
+
address@hidden
+Run @command{foo} with a reduced environment, preserving only the
+original @env{PATH} to avoid problems in locating @command{foo}.
address@hidden
+env - PATH="$PATH" foo
address@hidden example
+
address@hidden
+Run @command{foo} with the environment containing @samp{LOGNAME=rms},
address@hidden, and @samp{PATH=.:/gnubin:/hacks}, and guarantees
+that @command{foo} was found in the file system rather than a shell
+builtin.
address@hidden
+env foo
address@hidden example
+
address@hidden
+Run @command{nemacs} with the environment containing @samp{LOGNAME=foo},
address@hidden, @samp{PATH=.:/gnubin:/hacks}, and
address@hidden:0}.
address@hidden
+env DISPLAY=gnu:0 LOGNAME=foo nemacs
address@hidden example
+
address@hidden
+Attempt to run the program @command{/energy/--} (as that is the only
+possible path search result); if the command exists, the environment
+will contain @samp{LOGNAME=rms} and @samp{PATH=/energy}, and the
+arguments will be @samp{e=mc2}, @samp{bar}, and @samp{baz}.
address@hidden
+env -u EDITOR PATH=/energy -- e=mc2 bar baz
address@hidden example
+
address@hidden itemize
+
+
 The program accepts the following options.  Also see @ref{Common options}.
 Options must precede operands.

diff --git a/src/env.c b/src/env.c
index c20b057..4c0dead 100644
--- a/src/env.c
+++ b/src/env.c
@@ -16,72 +16,6 @@

 /* Richard Mlynarik and David MacKenzie */

-/* Options:
-   -
-   -i
-   --ignore-environment
-        Construct a new environment from scratch; normally the
-        environment is inherited from the parent process, except as
-        modified by other options.
-
-   -u variable
-   --unset=variable
-        Unset variable VARIABLE (remove it from the environment).
-        If VARIABLE was not set, does nothing.
-
-   -0
-   --null
-        When no program is specified, output environment information
-        terminated by NUL bytes rather than newlines.
-
-   variable=value (an arg containing a "=" character)
-        Set the environment variable VARIABLE to value VALUE.  VALUE
-        may be of zero length ("variable=").  Setting a variable to a
-        zero-length value is different from unsetting it.
-
-   --
-        Indicate that the following argument is not an option.
-        This is necessary when the program's name begins with "-",
-        but does not help if the program's name contains a "=".
-
-   The first remaining argument specifies a program to invoke;
-   it is searched for according to the specification of the PATH
-   environment variable, after environment modifications.  Any
-   arguments following that are passed as arguments to that program.
-
-   If no command name is specified following the environment
-   specifications, the resulting environment is printed.
-   This is like specifying a command name of "printenv".
-
-   Examples:
-
-   If the environment passed to "env" is
-        { LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
-
-   env - foo
-        runs "foo" in a null environment.
-
-   env foo
-        runs "foo" in the environment
-        { LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
-
-   env DISPLAY=gnu:0 nemacs
-        runs "nemacs" in the environment
-        { LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks DISPLAY=gnu:0 }
-
-   env - LOGNAME=foo /hacks/hack bar baz
-        runs the "hack" program on arguments "bar" and "baz" in an
-        environment in which the only variable is "LOGNAME".  Note that
-        the "-" option clears out the PATH variable, so one should be
-        careful to specify in which directory to find the program to
-        call.
-
-   env -u EDITOR LOGNAME=foo PATH=/energy -- e=mc2 bar baz
-        attempts to run the program "/energy/--" with arguments
-        "e=mc2", "bar" and "baz" in the environment
-        { LOGNAME=foo PATH=/energy }.
-*/
-
 #include <config.h>
 #include <stdio.h>
 #include <sys/types.h>
-- 
1.6.5.rc1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]