Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14260

Re: propagating environment variable via internal command

From Tomas Janousek <tomas.janousek@gooddata.com>
Newsgroups gnu.bash.bug
Subject Re: propagating environment variable via internal command
Date 2018-06-20 21:11 +0200
Message-ID <mailman.2317.1529525933.1292.bug-bash@gnu.org> (permalink)
References <20180620132525.enl5mlgyce54e4vc@doom> <2f12be85-7f2c-0f52-0119-b6c34060656a@case.edu>

Show all headers | View raw


Hi Chet and Tomáš,

On Wed, Jun 20, 2018 at 10:42:07AM -0400, Chet Ramey wrote:
> On 6/20/18 9:25 AM, Tomáš Čech wrote:
> >  $ /bin/sh
> >  sh-4.4$ VARIABLE=value set -o noglob
> >  sh-4.4$ env | grep VARIABLE
> >  VARIABLE=value
> >  sh-4.4$
> 
> Posix requires this behavior, which dates back to the Bourne shell, for
> assignment statements that precede special builtins:
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_14
> 
> It used to require the same behavior for assignment statements preceding
> shell function calls, but that was removed in the most recent update.

Thanks for the quick reply!

I followed the link in item 2 and there is:

  If the command name is a special built-in utility, variable assignments
  shall affect the current execution environment. Unless the set -a option is
  on (see set), it is unspecified:

    Whether or not the variables gain the export attribute during the
    execution of the special built-in utility

    Whether or not export attributes gained as a result of the variable
    assignments persist after the completion of the special built-in utility

It seems that dash implements this without the export, which means this
"surprising" example we came up with behaves "correctly", but there's still
this one, possibly more subtle:

  $ {da,}sh -c 'VAR=val set -o noglob; echo $VAR'
  val

So even though this does look a bit like behaviour defined by historic
implementations, I guess the conclusion is that we should just read up on
POSIX shells. :-)

Thank you Chet.

-- 
Tomáš Janoušek, DEV/SETI/CEP @ GoodData, +420 608 876 277

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: propagating environment variable via internal command Tomas Janousek <tomas.janousek@gooddata.com> - 2018-06-20 21:11 +0200

csiph-web