OILS / test / gold / case-in-subshell.sh View on Github | oilshell.org

37 lines, 20 significant
1#!/usr/bin/env bash
2
3foo=a
4case $foo in [0-9]) echo number;; [a-z]) echo letter;; esac
5
6# This works in bash, but syntax highlighting gets confused
7out=$(case $foo in [0-9]) echo number;; [a-z]) echo letter;; esac)
8echo $out
9
10# OK multiline works
11out=$(
12echo a
13echo b
14)
15echo $out
16
17# This does NOT work in bash, even though it's valid.
18#
19# http://lists.gnu.org/archive/html/bug-bash/2016-03/msg00065.html
20# Workarounds:
21# - append semicolon behind first 'esac', or
22# - insert any command line between the case statements, or
23# - use `...` instead of $(...)
24
25out=$(
26case $foo in
27 [0-9]) echo number;;
28 [a-z]) echo letter;;
29esac
30case $foo in
31 [0-9]) echo number;;
32 [a-z]) echo letter;;
33esac
34)
35echo $out
36
37