summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2011-06-17 13:03:49 +0000
committerjilles <jilles@FreeBSD.org>2011-06-17 13:03:49 +0000
commitc7a72567a8474dcecd93215073976b04171d1144 (patch)
treed74a77976194c0d5d68bbf18c002a166b97300a5 /tools
parentf405f6d6f8e62f9714eb668d35001c794646022b (diff)
downloadFreeBSD-src-c7a72567a8474dcecd93215073976b04171d1144.zip
FreeBSD-src-c7a72567a8474dcecd93215073976b04171d1144.tar.gz
sh: Add case statement fallthrough (with ';&' instead of ';;').
Replacing ;; with the new control operator ;& will cause the next list to be executed as well without checking its pattern, continuing until a list ends with ;; or until the end of the case statement. This is like omitting "break" in a C "switch" statement. The sequence ;& was formerly invalid. This feature is proposed for the next POSIX issue in Austin Group issue #449.
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/bin/sh/builtins/case9.039
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/builtins/case9.0 b/tools/regression/bin/sh/builtins/case9.0
new file mode 100644
index 0000000..476caec
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/case9.0
@@ -0,0 +1,39 @@
+# $FreeBSD$
+
+errors=0
+
+f() {
+ result=
+ case $1 in
+ a) result=${result}a ;;
+ b) result=${result}b ;&
+ c) result=${result}c ;&
+ d) result=${result}d ;;
+ e) result=${result}e ;&
+ esac
+}
+
+check() {
+ f "$1"
+ if [ "$result" != "$2" ]; then
+ printf "For %s, expected %s got %s\n" "$1" "$2" "$result"
+ errors=$((errors + 1))
+ fi
+}
+
+check '' ''
+check a a
+check b bcd
+check c cd
+check d d
+check e e
+
+if ! (case 1 in
+ 1) false ;&
+ 2) true ;;
+esac) then
+ echo "Subshell bad"
+ errors=$((errors + 1))
+fi
+
+exit $((errors != 0))
OpenPOWER on IntegriCloud