FreeBSD Bugzilla – Attachment 81390 Details for
Bug 116559
make case statement of Bourne shell IEEE 1003.2-conformant
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
sh.patch
sh.patch (text/plain), 2.16 KB, created by
Eygene Ryabinkin
on 2007-09-22 19:20:02 UTC
(
hide
)
Description:
sh.patch
Filename:
MIME Type:
Creator:
Eygene Ryabinkin
Created:
2007-09-22 19:20:02 UTC
Size:
2.16 KB
patch
obsolete
>According to the standard (http://opengroup.org/onlinepubs/000095399, >Shell and Utilities Volume (XCU), Case Conditional Construct), the >'case' statement shall return zero if no patterns were matched. > >Currently, Bourne shell in FreeBSD does not change the exit code >on the 'case' construct that had not matched anything; it is >completely transparent in this regard. > >The following test script shall not produce any messages with the >1003.2-conformant shells and its return code shall be zero: >----- >err () { > echo "ERROR: $@" >} > >case_and_immediate () { > false > case Ultra in > Super) > false > ;; > Hyper) > true > ;; > esac && echo ok >} > >case_while_immediate () { > false > while case Ultra in Super) break ;; esac > do > echo ok > break > done >} > >retval=0 > >for test in \ > case_and_immediate \ > case_while_immediate >do > result=`$test` > if test "$result" != ok; then > err "$test" failed > retval=$(($retval + 1)) > fi >done > >exit $retval >----- > >The real rationale for this change is that some utilities are >using constructs like >----- >while case "#?" in 0) break ;; esac >do > case "$1" in > --someflag) > ... > ;; > ... > esac >done >----- >for the argument parsing. The example I had before my eyes is >Git 1.5.3.2, script named git-commit. > >Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru> >--- > eval.c | 1 + > sh.1 | 4 ++++ > 2 files changed, 5 insertions(+), 0 deletions(-) > >diff --git a/eval.c b/eval.c >index 9b41f63..6d24df2 100644 >--- a/eval.c >+++ b/eval.c >@@ -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) { >diff --git a/sh.1 b/sh.1 >index 72aa5c5..41779fe 100644 >--- a/sh.1 >+++ b/sh.1 >@@ -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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 116559
: 81390