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


Groups > gnu.bash.bug > #14260 > unrolled thread

Re: propagating environment variable via internal command

Started byTomas Janousek <tomas.janousek@gooddata.com>
First post2018-06-20 21:11 +0200
Last post2018-06-20 21:11 +0200
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#14260 — Re: propagating environment variable via internal command

FromTomas Janousek <tomas.janousek@gooddata.com>
Date2018-06-20 21:11 +0200
SubjectRe: propagating environment variable via internal command
Message-ID<mailman.2317.1529525933.1292.bug-bash@gnu.org>
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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web