bourne: $var in ' )' part of 'case' statement

This is part of a code
Code:
case "$driver" in
            $fw_devs )
                ...
Works:
Code:
fw_devs=ral
However, this doesn't:
Code:
fw_devs='ral | run'
fw_devs='ral|run'

Coping raw string from var, worked:
Code:
case "$driver" in
            ral|run )
                ...
 
You cannot assign multiple values to a variable that way. This will only make this a literal variable containing the string "ral|run" or "ral | run". You can use arrays (driver[0]=ral, driver[1]=run, echo ${driver[0]}, echo ${driver[1]}), but calling those from a case script the way you would like to may create more work than simply putting the multiple choices in the case script itself. There may be other solutions, of course.

Experiment with [cmd=]echo ${driver[*]}[/cmd] maybe. This will print the entire array.
 
Apart from eval, another trick that sometimes works is to reverse word and pattern, for example:
Code:
fw_devs='ral|run'
case "|$fw_devs|" in
*"|$driver|"*) echo yes ;;
*) echo no ;;
esac

Make sure $driver does not contain a "|" symbol.
 
@ DutchDaemon -> bourne shell doesn't have an arrays.
@ wblock -> Thx! I've put whole 'case' statement in eval "".
@ jilles -> Excellent hack! However, my 'case' statement, is too complex, for your hack.
 
Back
Top