You can create a dynamic case statement in bash by doing the following:
1) ensure the list is PIPE (|) seperated. IE. red|green|blue
2) wrap your case statement in an eval
For example:
valid="red|green|blue"
eval "case "$choice" in
$valid)
echo do something good here
;;
*)
echo invalid colour
;;
esac"
This works for simple variable processing, I can not guarantee this will work in all cases.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…