Question:
Linux Bash Case Statements - How to Make a Statement for a Number Range?
owt76
2007-04-22 11:08:47 UTC
Hi,

I'm trying to make a case statement where it tests to see if a number falls into a certain range. This is what it looks like (just a portion of the code):

case $score in
[90-100]) echo "A grade"
;;
[80-89]) echo "B grade"
;;
*) echo "Very bad grade!!!"
;;
esac

I don't think I have the correct syntax for the number ranges in the case statements. I've searched and searched and could not find what the correct syntax is - can someone help?
Three answers:
sfpiano
2007-04-22 11:36:05 UTC
case $score in

[90-100]*) echo "A grade"

;;

[80-89]*) echo "B grade"

;;

*) echo "Very bad grade!!!"

;;

esac
graybill
2016-10-02 11:55:34 UTC
Bash Case Statement
anonymous
2016-12-28 08:37:39 UTC
Linux Case Statement


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...