bash - Use Variable with multiple options in Case statement -
is possible following (and how ?)(,resp. why not ?):
match="--opt1 | --opt2" while true ; case $1 in $match) echo "option $2" found; shift 2;; *) unknown option; exit 1; esac done
for reason dont understand doesnt work. however, having 1 alternative match="--opt1" fine.
edit 1: possible solution
instead of going case statement 1 check if given option occurs in string of multiple allowed options, instance using grep , if. full dynamically 1 consider follwoing solution, might combined or embedded within case statement:
while true ; if [ -n "$(echo $matches|grep -- $1)" ]; echo "found option $1 value $2" shift 2 fi done
the pipe character, when embedded in parameter value, treated literally, not syntax. you'll have use multiple strings:
while true; case $1 in $match1 | $match2 ) # etc
Comments
Post a Comment