]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Document shell function environment pitfall.
authorEric Blake <ebb9@byu.net>
Tue, 14 Oct 2008 17:26:58 +0000 (11:26 -0600)
committerEric Blake <ebb9@byu.net>
Tue, 14 Oct 2008 17:28:09 +0000 (11:28 -0600)
* doc/autoconf.texi (Shell Functions): Document bugs in bash,
Solaris /bin/sh.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
doc/autoconf.texi

index d6337f6a9910e144441dafead78a99cc32b1c5fd..071f2a9c89f0311e6997ec5ed6be2311479aa448 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-10-14  Eric Blake  <ebb9@byu.net>
+
+       Document shell function environment pitfall.
+       * doc/autoconf.texi (Shell Functions): Document bugs in bash,
+       Solaris /bin/sh.
+
 2008-10-14  Paolo Bonzini  <bonzini@gnu.org>
 
        Use m4_require to implement AS_REQUIRE.
index ff81c2ecd2bcfb793fb5965797d05fdcb40a9bbd..dc8646263350c3f676c30b5837173923e25e0e8d 100644 (file)
@@ -14225,6 +14225,23 @@ For example, Korn shells reset and restore trace output (@samp{set -x})
 and other options upon function entry and exit.  Inside a function,
 @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,
+@command{bash} 3.2 breaks the Posix rule that the assignment must not affect
+the current environment, but only when Posix compliance is requested!
+
+@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'}
+@result{}1
+@result{}
+$ @kbd{bash -c 'set -o posix; func()@{ echo $a;@}; a=1 func; echo $a'}
+@result{}1
+@result{}1
+@end example
+
 Some ancient Bourne shell variants with function support did not reset
 @samp{$@var{i}, @var{i} >= 0}, upon function exit, so effectively the
 arguments of the script were lost after the first function invocation.