| 1 | #!/usr/bin/env bash
|
| 2 |
|
| 3 | foo=a
|
| 4 | case $foo in [0-9]) echo number;; [a-z]) echo letter;; esac
|
| 5 |
|
| 6 | # This works in bash, but syntax highlighting gets confused
|
| 7 | out=$(case $foo in [0-9]) echo number;; [a-z]) echo letter;; esac)
|
| 8 | echo $out
|
| 9 |
|
| 10 | # OK multiline works
|
| 11 | out=$(
|
| 12 | echo a
|
| 13 | echo b
|
| 14 | )
|
| 15 | echo $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 |
|
| 25 | out=$(
|
| 26 | case $foo in
|
| 27 | [0-9]) echo number;;
|
| 28 | [a-z]) echo letter;;
|
| 29 | esac
|
| 30 | case $foo in
|
| 31 | [0-9]) echo number;;
|
| 32 | [a-z]) echo letter;;
|
| 33 | esac
|
| 34 | )
|
| 35 | echo $out
|
| 36 |
|
| 37 |
|