How to make case statement match a number range?

Bash case doesn’t work with numbers ranges. [] is for shell patterns.

for instance this case [1-3]5|6) will work for 15 or 25 or 35 or 6.

Your code should look like this:

i=10
a=1
b=0.65
if [ "$a" != "$b" ] ; then
   case $i in
        1|2|5) echo "Not OK"; ;;
        9|10|12) echo "may be ok"; ;;
        *) echo "no clue - $i"; ;;
   esac;
fi

If i can be real between 9 and 10 then you’ll need to use if (instead of case) with ranges.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)