diff options
author | jilles <jilles@FreeBSD.org> | 2012-01-15 20:04:05 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-01-15 20:04:05 +0000 |
commit | 6253417a7002be7641015b22d63bbe274869ed0b (patch) | |
tree | f70a5342132acdff57c298b57df7abd30ebb8dfb /bin/sh | |
parent | 67dd0ca2547a8ce8b86b7f88b4ccee6e14abeb4c (diff) | |
download | FreeBSD-src-6253417a7002be7641015b22d63bbe274869ed0b.zip FreeBSD-src-6253417a7002be7641015b22d63bbe274869ed0b.tar.gz |
sh: Fix two bugs with case and exit status:
* If no pattern is matched, POSIX says the exit status shall be 0 (even if
there are command substitutions).
* If a pattern is matched and there are no command substitutions, the first
command should see the $? from before the case command, not always 0.
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/eval.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index e3b93a3..07b0d64 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -378,7 +378,6 @@ evalcase(union node *n, int flags) setstackmark(&smark); arglist.lastp = &arglist.list; oexitstatus = exitstatus; - exitstatus = 0; expandarg(n->ncase.expr, &arglist, EXP_TILDE); for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) { for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) { @@ -392,11 +391,14 @@ evalcase(union node *n, int flags) return (NULL); cp = cp->nclist.next; } + if (cp->nclist.body == NULL) + exitstatus = 0; return (cp->nclist.body); } } } popstackmark(&smark); + exitstatus = 0; return (NULL); } |