Consider the following:

true
a=$? b=`exit 1` b=$? >`echo /dev/null; exit 2`
echo $? $a $b

Having read the relevant sections of the standard a couple times, I
would expect the output to be `1 0 0'; but that's not the case with
most shells. Below are what each shell I have on my computer output
for that script.

        ?  a  b
bash    2  0  1
bosh    2  0  0
dash    1  0  0
ksh     2  0  1
mksh    1  0  0
yash    2  0  0
zsh     1  2  1

Now, I wonder, what did I miss? Where does it say in the standard that
the value of parameter `?' is affected by redirections, and that its
value depends on assignments that appear earlier in the same command?

Regards,
Oğuz

  • $? in a simple comman... Oğuz via austin-group-l at The Open Group

Reply via email to