I'm trying to write a Bash script that uses a variable as a pattern in a case statement. However, I just cannot get it to work.
Case statement:
case "$1" in
$test)
echo "matched"
;;
*)
echo "didn't match"
;;
esac
I've tried this with assigning $test
as aaa|bbb|ccc
, (aaa|bbb|ccc)
, [aaa,bbb,ccc]
and several other combinations. I also tried these as the pattern in the case statement: @($test)
, @($(echo $test))
, $($test)
. Also no success.
For clarity, I would like the variable to represent multiple patterns like this:
case "$1" in
aaa|bbb|ccc)
echo "matched"
;;
*)
echo "didn't match"
;;
esac