[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Reading the $? of an assignment (Was: expr ... and `expr ...` retur
From: |
Akim Demaille |
Subject: |
FYI: Reading the $? of an assignment (Was: expr ... and `expr ...` return different results on QNX 4.2.5) |
Date: |
30 Nov 2000 18:55:21 +0100 |
User-agent: |
Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) |
>>>>> "Pavel" == Pavel Roskin <address@hidden> writes:
Pavel> It's a different bug. With ash, you shouldn't rely on $? after
Pavel> assignments _unless_ backticks are used. In this case, you
Pavel> cannot rely on $? _if_ backticks are used.
Index: ChangeLog
from Akim Demaille <address@hidden>
* doc/autoconf.texi (Assignments): Don't read $? after an
assignment.
Index: doc/autoconf.texi
===================================================================
RCS file: /cvs/autoconf/doc/autoconf.texi,v
retrieving revision 1.401
diff -u -u -r1.401 autoconf.texi
--- doc/autoconf.texi 2000/11/30 17:27:32 1.401
+++ doc/autoconf.texi 2000/11/30 17:48:12
@@ -5075,15 +5075,6 @@
@itemize @bullet
@item
-don't rely on variable assignment setting @samp{$?} unless the
-assignment involves command substitution:
-
address@hidden
-false || foo=bar && echo "Not portable"
-false || foo=`bar` && echo "Portable"
address@hidden example
-
address@hidden
don't use @samp{$?} after expanding empty or unset variables:
@example
@@ -5345,6 +5336,24 @@
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}.
+Don't rely on the exit status of an assignment: Ash 0.2 does not change
+the status and propagates that of the last statement:
+
address@hidden
+$ false || foo=bar; echo $?
+1
+$ false || foo=`:`; echo $?
+0
address@hidden example
+
address@hidden
+and to make things even worse, @sc{qnx 4.25} just sets the exit status
+to 0 in any case:
+
address@hidden
+$ foo=`exit 1`; echo $?
+0
address@hidden example
To assign default values follow this algorithm:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: Reading the $? of an assignment (Was: expr ... and `expr ...` return different results on QNX 4.2.5),
Akim Demaille <=