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

Re: weird ksh eval behavior



Ralf Wildenhues <Ralf_(_dot_)_Wildenhues_(_at_)_gmx_(_dot_)_de> writes:

> is this behavior considered "common knowledge" or should it be
> mentioned in the Autoconf shell portability section?

The latter, I think.  I installed this:

2005-12-01  Paul Eggert  <eggert_(_at_)_cs_(_dot_)_ucla_(_dot_)_edu>

	* doc/autoconf.texi (Shellology): Document eval $? problem
	with ash.
	(Limitations of Builtins): Likewise.

--- autoconf.texi	10 Nov 2005 18:57:58 -0000	1.933
+++ autoconf.texi	1 Dec 2005 21:02:40 -0000	1.934
@@ -9783,13 +9783,16 @@ To be compatible with Ash 0.2:
 
 @itemize @minus
 @item
-don't use @samp{$?} after expanding empty or unset variables:
+don't use @samp{$?} after expanding empty or unset variables,
+or at the start of an @command{eval}:
 
 @example
 foo=
 false
 $foo
-echo "Don't use it: $?"
+echo "Do not use it: $?"
+false
+eval 'echo "Do not use it: $?"'
 @end example
 
 @item
@@ -11120,6 +11123,25 @@ $foo
 EOF
 @end example
 
+
+_(_at_)_item @command{eval}
+_(_at_)_c -----------------
+_(_at_)_prindex @command{eval}
+In some shell implementations (e.g., @command{ash}, OpenBSD 3.8
+_(_at_)_command{sh}, @command{pdksh} v5.2.14 99/07/13.2, and @command{zsh}
+4.2.5), the arguments of @samp{eval} are evaluated in a context where
+_(_at_)_samp{$?} is 0, so they exhibit behavior like this:
+
+_(_at_)_example
+$ false; eval 'echo $?'
+0
+_(_at_)_end example
+
+The correct behavior here is to assign a nonzero value to @samp{foo},
+but portable scripts should not rely on this.
+
+You should not rely on @code{LINENO} within @command{eval}.
+_(_at_)_xref{Special Shell Variables}.
 
 @item @command{exit}
 @c -----------------