The man
page says that case
statements use "filename expansion pattern matching".
I usually want to have short names for some parameters, so I go:
case $1 in
req|reqs|requirements) TASK="Functional Requirements";;
met|meet|meetings) TASK="Meetings with the client";;
esac
logTimeSpentIn "$TASK"
I tried patterns like req*
or me{e,}t
which I understand would expand correctly to match those values in the context of filename expansion, but it doesn't work.
I don't think you can use braces.
According to the Bash manual about case in Conditional Constructs.
Nothing about Brace Expansion unfortunately.
So you'd have to do something like this:
if
andgrep -E
more portable solutionFor portability, I recommend that you just use
if
statements andgrep -E
which supports extended regular expressions, e.g.:POSIX 7
Bash appears to follow POSIX by default without
shopt
as mentioned by https://stackoverflow.com/a/4555979/895245Here is the quote: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_01 section "Case Conditional Construct":
and then http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13 section "2.13. Pattern Matching Notation" only mentions
?
,*
and[]
.Brace expansion doesn't work, but
*
,?
and[]
do. If you setshopt -s extglob
then you can also use extended pattern matching:?()
- zero or one occurrences of pattern*()
- zero or more occurrences of pattern+()
- one or more occurrences of pattern@()
- one occurrence of pattern!()
- anything except the patternHere's an example: