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.
This commit is contained in:
parent
4aecc339cf
commit
92371efca2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=230154
@ -378,7 +378,6 @@ evalcase(union node *n, int flags)
|
|||||||
setstackmark(&smark);
|
setstackmark(&smark);
|
||||||
arglist.lastp = &arglist.list;
|
arglist.lastp = &arglist.list;
|
||||||
oexitstatus = exitstatus;
|
oexitstatus = exitstatus;
|
||||||
exitstatus = 0;
|
|
||||||
expandarg(n->ncase.expr, &arglist, EXP_TILDE);
|
expandarg(n->ncase.expr, &arglist, EXP_TILDE);
|
||||||
for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
|
for (cp = n->ncase.cases ; cp ; cp = cp->nclist.next) {
|
||||||
for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
|
for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
|
||||||
@ -392,11 +391,14 @@ evalcase(union node *n, int flags)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
cp = cp->nclist.next;
|
cp = cp->nclist.next;
|
||||||
}
|
}
|
||||||
|
if (cp->nclist.body == NULL)
|
||||||
|
exitstatus = 0;
|
||||||
return (cp->nclist.body);
|
return (cp->nclist.body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
popstackmark(&smark);
|
popstackmark(&smark);
|
||||||
|
exitstatus = 0;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
tools/regression/bin/sh/builtins/case14.0
Normal file
5
tools/regression/bin/sh/builtins/case14.0
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
case `false` in
|
||||||
|
no) exit 3 ;;
|
||||||
|
esac
|
5
tools/regression/bin/sh/builtins/case15.0
Normal file
5
tools/regression/bin/sh/builtins/case15.0
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
case x in
|
||||||
|
`false`) exit 3 ;;
|
||||||
|
esac
|
7
tools/regression/bin/sh/builtins/case16.0
Normal file
7
tools/regression/bin/sh/builtins/case16.0
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
f() { return 42; }
|
||||||
|
f
|
||||||
|
case x in
|
||||||
|
x) [ $? = 42 ] ;;
|
||||||
|
esac
|
Loading…
Reference in New Issue
Block a user