The exit status of a case statement where none of the patterns is matched
is supposed to be 0, not the status of the previous command. Reported by: Eygene Ryabinkin PR: 116559 Approved by: re (gnn)
This commit is contained in:
parent
265e8a9acc
commit
aafd6a87a6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=172440
@ -367,6 +367,7 @@ 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 && evalskip == 0 ; cp = cp->nclist.next) {
|
||||
for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
|
||||
|
@ -861,6 +861,10 @@ described later),
|
||||
separated by
|
||||
.Dq Li \&|
|
||||
characters.
|
||||
The exit code of the
|
||||
.Ic case
|
||||
command is the exit code of the last command executed in the list or
|
||||
zero if no patterns were matched.
|
||||
.Ss Grouping Commands Together
|
||||
Commands may be grouped by writing either
|
||||
.Bd -literal -offset indent
|
||||
|
13
tools/regression/bin/sh/builtins/case1.0
Normal file
13
tools/regression/bin/sh/builtins/case1.0
Normal file
@ -0,0 +1,13 @@
|
||||
#$FreeBSD$
|
||||
f()
|
||||
{
|
||||
false
|
||||
case $1 in
|
||||
foo) true ;;
|
||||
bar) false ;;
|
||||
esac
|
||||
}
|
||||
|
||||
f foo || exit 1
|
||||
f bar && exit 1
|
||||
f quux || exit 1
|
Loading…
Reference in New Issue
Block a user