diff --git a/bin/sh/eval.c b/bin/sh/eval.c index e3b93a3e61ea..07b0d64828f7 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); } diff --git a/tools/regression/bin/sh/builtins/case14.0 b/tools/regression/bin/sh/builtins/case14.0 new file mode 100644 index 000000000000..0338e8a224e3 --- /dev/null +++ b/tools/regression/bin/sh/builtins/case14.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +case `false` in +no) exit 3 ;; +esac diff --git a/tools/regression/bin/sh/builtins/case15.0 b/tools/regression/bin/sh/builtins/case15.0 new file mode 100644 index 000000000000..09b0e1133544 --- /dev/null +++ b/tools/regression/bin/sh/builtins/case15.0 @@ -0,0 +1,5 @@ +# $FreeBSD$ + +case x in +`false`) exit 3 ;; +esac diff --git a/tools/regression/bin/sh/builtins/case16.0 b/tools/regression/bin/sh/builtins/case16.0 new file mode 100644 index 000000000000..24303027ba91 --- /dev/null +++ b/tools/regression/bin/sh/builtins/case16.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +f() { return 42; } +f +case x in +x) [ $? = 42 ] ;; +esac