I am having issues with my case statement not returning values. I am new to using cases and not a computer programmer. Any advice is helpful
############################# Chose GrADS or OpenGrADS #########################
while true; do
read -p "Would you like to install OpenGrADS or GrADS? (OpenGrADS/GrADS)" yn
case $yn in
[OpenGrADS]* )
export GRADS_PICK=1 #variable set for grads or opengrads choice
break
;;
[GrADS]* )
export GRADS_PICK=2 #variable set for grads or opengrads choice
break
;;
* )
echo " "
echo "Please answer OpenGrADS or GrADS (case sensative).";;
esac
done
CodePudding user response:
Your code is almost correct, your mistake was how you checked the input. Be careful with * because it's a special character in most of the programming languages and especially bash/unix.
while read -p "Would you like to install OpenGrADS or GrADS? (OpenGrADS/GrADS)" yn; do
case $yn in
OpenGrADS)
echo "first choice"
export GRADS_PICK=1 #variable set for grads or opengrads choice
break
;;
GrADS)
echo "second choice"
export GRADS_PICK=2 #variable set for grads or opengrads choice
break
;;
* )
echo " "
echo "Please answer OpenGrADS or GrADS (case sensative).";;
esac
done
EDIT: quotes aren't necessary. (thanks chepner and Gordon Davisson)