Select random variable in Bash -
i need print value of (i.e. cadetblue) random var colour_* tried"
echo $colour_${number} echo "$colour_${number}"
and many others , none working.
i have bash:
#!/bin/bash number=$[ ( $random % 9 ) + 1 ] echo $number colour_1=aliceblue colour_2=antiquewhite colour_3=antiquewhite1 colour_4=antiquewhite2 colour_5=antiquewhite3 colour_6=antiquewhite4 colour_7=blanchedalmond colour_8=blueviolet colour_9=cadetblue echo $colour_$number
instead of saying
echo $colour_$number
say:
color=colour_${number} echo ${!color}
you can read more indirect expansion here.
Comments
Post a Comment