On 9/1/21 4:59 PM, (Joerg Schilling) wrote:
"Chet Ramey via austin-group-l at The Open Group"
<[email protected]> wrote:
Given the following:
(exit 42)
a=$? b=`false` b=$?
echo $? $a $b
Bash prints 1 42 1.
The original (v7) bourne shell and the rest of the research line through v9
prints 1 1 (b is set to the empty string). That implies that it executes
the assignment statements in reverse order, in addition to carrying $?
through the sequence of assignments.
You are right, the original Bourne Shell for unknown reasons did evaluate a
series of shell variable assignments in reverse order. That was changed in
ksh88 and in bosh.
The SVR4.2 shell prints 1 42 1. I imagine the rest of the SVR4 line sh is
the same.
Something called SVR4.2 does not really exist. It was a minor change compared
to SvR4 announced by Novell short before they sold the Copyright to SCO. >
I know of no customers for SVR4.2... even SCO seems to only used it internally
in their project Monterey that was abandoned by IBM.
And yet it existed as a product. Univel probably had Unixware customers
they didn't tell you about.
You can find it for download if you look for it, I suspect.
There have been major changes in the Bourne Shell for SvR4, but the $? was not
touched. So you are mistaken.
Sure, I didn't have SVR4 to test against when I wrote that.
The important thing to know here is that the Bourne Shell has some
checkpoints that update the intermediate value of $?. Since that changed in
ksh88 and since POSIX requires a different behavior compared to the Bourne
Shell, I modified one checkpoint in bosh to let it match POSIX.
Interesting, since ksh88 (Solaris 10 11/16/88i) and ksh93 (93u+ 2012-08-01)
both print
1 42 1
Odd that POSIX would specify something different, isn't it?
(exit 42); a=$? b=`false` b=$?; echo $? $a $b
prints
1 42 42
in bosh and
1 1
in the SvR4 Bourne Shell.
It echoes 255 255 with the Solaris 10 /bin/sh (b is again null). It looks
like /bin/false exits with status 255, the Solaris 10 sh still performs
the assignments in reverse order, and the Solaris 10 version of the SVR4 sh
sets $? from the result of each command substitution.
In any case, kre's point stands: the original Bourne shell (and, for that
matter, the POSIX base implementation) set $? as each command substitution
finishes.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/