diff options
author | jilles <jilles@FreeBSD.org> | 2012-01-22 14:00:33 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-01-22 14:00:33 +0000 |
commit | ae59680813890a93e9eaebbf69c2d63b852e512f (patch) | |
tree | 2e29d787749cfc02654715cbca4bcb06b3c510ec /bin | |
parent | f317ff0f6559bac3c7a0ee926ba002b29cdf2d53 (diff) | |
download | FreeBSD-src-ae59680813890a93e9eaebbf69c2d63b852e512f.zip FreeBSD-src-ae59680813890a93e9eaebbf69c2d63b852e512f.tar.gz |
sh: Fix $? in the first command of a 'for'.
In the first command of a 'for', $? should be the exit status of the last
pipeline (command substitution in the word list or command before 'for'),
not always 0.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/eval.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index f4f69d9..a5f0aff 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -348,6 +348,7 @@ evalfor(union node *n, int flags) union node *argp; struct strlist *sp; struct stackmark smark; + int status; setstackmark(&smark); arglist.lastp = &arglist.list; @@ -357,11 +358,12 @@ evalfor(union node *n, int flags) } *arglist.lastp = NULL; - exitstatus = 0; loopnest++; + status = 0; for (sp = arglist.list ; sp ; sp = sp->next) { setvar(n->nfor.var, sp->text, 0); evaltree(n->nfor.body, flags); + status = exitstatus; if (evalskip) { if (evalskip == SKIPCONT && --skipcount <= 0) { evalskip = 0; @@ -374,6 +376,7 @@ evalfor(union node *n, int flags) } loopnest--; popstackmark(&smark); + exitstatus = status; } |