-2

my target is to verify the range of number with (only with - case + esac ) , and print the range

so for example

if number is between 0-80 , case will print

 >=0<=80

or if range is between 81-100 then case will print

 >=81<=100

and so on....

the problem with my script print only >=0<=90 only if number between 0-9 ?

how to fix my script , so it will print according to number range ?

#!/bin/ksh

read number 

case $number in 
    [0-80])  echo ">=0<=80";; 
    [81-100]) echo ">=81<=100";; 
    [101-120]) echo ">=101<=120";;
    [121-300]) echo ">=121<=300";;
esac 
mgorven
  • 30,615
  • 7
  • 79
  • 122
yael
  • 2,433
  • 5
  • 31
  • 43

1 Answers1

0

In zsh (which ksh is symlinked to on my system) you need to use <> for numerical ranges:

case $number in
    <0-80>)  echo ">=0<=80";;
    <81-100>) echo ">=81<=100";;
    <101-120>) echo ">=101<=120";;
    <121-300>) echo ">=121<=300";;
esac
mgorven
  • 30,615
  • 7
  • 79
  • 122