autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH] Yet another shell function prerequisite!


From: Eric Blake
Subject: Re: [PATCH] Yet another shell function prerequisite!
Date: Tue, 14 Oct 2008 17:54:52 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> $ bash -c 'func(){ echo "${a+set}";}; a=1 func; echo $a'
> set
> 
> $ bash -c 'set -o posix;func(){ echo "${a+set}";}; a=1 func; echo $a'
> set
> 1
> $
> 
> In other words, asking bash for POSIX compliance actually makes bash violate 
> POSIX by leaking the assignment beyond the function call; since POSIX 
requires 
> that "Otherwise, the variable assignments shall be exported for the execution 
> environment of the command and shall not affect the current execution 
> environment (except for special built-ins)."

Never mind.  Bash is doing the correct thing, since:
"When a function is executed, it shall have the syntax-error and variable-
assignment properties described for special built-in utilities"
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_0
9_05

zsh has the same bipolar behavior, depending on the use of 'emulate sh', 
leaving at least ash and Solaris 8 ksh with bugs.

So I'm applying this followup (sorry for the churn):

From: Eric Blake <address@hidden>
Date: Tue, 14 Oct 2008 11:52:38 -0600
Subject: [PATCH] Correct previous patch.

* doc/autoconf.texi (Shell Functions): Bash obeys Posix, after
all.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog         |    4 ++++
 doc/autoconf.texi |    8 ++++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 071f2a9..8a4504c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-10-14  Eric Blake  <address@hidden>
 
+       Correct previous patch.
+       * doc/autoconf.texi (Shell Functions): Bash obeys Posix, after
+       all.
+
        Document shell function environment pitfall.
        * doc/autoconf.texi (Shell Functions): Document bugs in bash,
        Solaris /bin/sh.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index dc86462..ddd0638 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -14226,15 +14226,15 @@ Shell Functions
 @acronym{IRIX} sh sets @samp{$0} to the function name.
 
 It is not portable to pass temporary environment variables to shell
-functions.  Solaris @command{/bin/sh} does not see the variable.  Meanwhile,
address@hidden 3.2 breaks the Posix rule that the assignment must not affect
-the current environment, but only when Posix compliance is requested!
+functions.  Solaris @command{/bin/sh} does not see the variable.
+Meanwhile, not all shells follow the Posix rule that the assignment must
+affect the current environment in the same manner as special built-ins.
 
 @example
 $ @kbd{/bin/sh -c 'func()@{ echo $a;@}; a=1 func; echo $a'}
 @result{}
 @result{}
-$ @kbd{bash -c 'func()@{ echo $a;@}; a=1 func; echo $a'}
+$ @kbd{ash -c 'func()@{ echo $a;@}; a=1 func; echo $a'}
 @result{}1
 @result{}
 $ @kbd{bash -c 'set -o posix; func()@{ echo $a;@}; a=1 func; echo $a'}
-- 
1.6.0.2







reply via email to

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