From 1740faf5e03b07410065fc0e2a1d45179c29f5d1 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 7 Jun 2000 11:57:11 +0000 Subject: [PATCH] `foo=1 foo=2 cmd' has an undefined behavior. * acgeneral.m4 (_AC_COMPUTE_INT_COMPILE): Do not put two shell variable assignments in one shell command. * doc/autoconf.texi (Shell Substitutions): Document. --- ChangeLog | 8 ++++++++ acgeneral.m4 | 6 +++--- doc/autoconf.texi | 5 +++++ lib/autoconf/general.m4 | 6 +++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2d2e945..8fd82eb8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-06-07 Philippe De Muyter + + `foo=1 foo=2 cmd' has an undefined behavior. + + * acgeneral.m4 (_AC_COMPUTE_INT_COMPILE): Do not put two shell + variable assignments in one shell command. + * doc/autoconf.texi (Shell Substitutions): Document. + 2000-06-07 Steven G. Johnson * aclang.m4 (AC_F77_LIBRARY_LDFLAGS): Fix problem on Cray due to diff --git a/acgeneral.m4 b/acgeneral.m4 index 0f939960..b1a22e15 100644 --- a/acgeneral.m4 +++ b/acgeneral.m4 @@ -3178,14 +3178,14 @@ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= 0])], [ac_lo=0 ac_try=0 while true; do AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_try])], - [ac_hi=$ac_try; break], - [ac_lo=`expr $ac_try + 1` ac_try=`expr 2 '*' $ac_try + 1`]) + [ac_hi=$ac_try; break], + [ac_lo=`expr $ac_try + 1`; ac_try=`expr 2 '*' $ac_try + 1`]) done], [ac_hi=-1 ac_try=-1 while true; do AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_try])], [ac_lo=$ac_try; break], - [ac_hi=`expr $ac_try - 1` ac_try=`expr 2 '*' $ac_try`]) + [ac_hi=`expr $ac_try - 1`; ac_try=`expr 2 '*' $ac_try`]) done]) # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 838fcaf7..586eb164 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -4718,6 +4718,11 @@ If the value is a literal string, it should be quoted: otherwise some shells, such as on Digital Unix V 5.0, will die because of a @emph{bad substitution}. +When setting several variables in a row, be aware that the order of the +evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo} +gives @samp{1} with sh on Solaris, but @samp{2} with bash. You must use +@samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}. + Contrary to a persistent urban legend, the Bourne shell does not systematically split variables and backquoted expressions, in particular, the following code: diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index 0f939960..b1a22e15 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -3178,14 +3178,14 @@ AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= 0])], [ac_lo=0 ac_try=0 while true; do AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) <= $ac_try])], - [ac_hi=$ac_try; break], - [ac_lo=`expr $ac_try + 1` ac_try=`expr 2 '*' $ac_try + 1`]) + [ac_hi=$ac_try; break], + [ac_lo=`expr $ac_try + 1`; ac_try=`expr 2 '*' $ac_try + 1`]) done], [ac_hi=-1 ac_try=-1 while true; do AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([$3], [($1) >= $ac_try])], [ac_lo=$ac_try; break], - [ac_hi=`expr $ac_try - 1` ac_try=`expr 2 '*' $ac_try`]) + [ac_hi=`expr $ac_try - 1`; ac_try=`expr 2 '*' $ac_try`]) done]) # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do