We help IT Professionals succeed at work.

case statement Linux

327 Views
Last Modified: 2013-12-26
How do I make a case statement that will allow me to show a range from 90 to 100? I have tried a lot of combinations and nothing worked yet. I am using Darwin.
This is an example of what I have been working on.

case $blah in
[9-1][0-00]) echo "statement" ;;
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
if think a normal
if ( $blah >=  90 &&  $blah <=100 )
would be more efficient in the code...
Agreed
Top Expert 2005

Commented:
Rather

if [ $blah -ge 90 -a $blah -le 100 ]; then
 echo statement
elif [ $blah -gt 100 ]; then
 echo "greater than 100"
fi

Author

Commented:
I thought about doing that but case is how I have to do this.
Top Expert 2005

Commented:
I assume bash

case $blah in
 9?|100) echo "OK"
esac
Top Expert 2005
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I also want to thank the rest who took time to do the if statements. One more question how do I do 0-60 without a car :) I know how to do 60-69 [6-6][0-9], and other numbers like that but I am having a hard time with the zeros.
Top Expert 2005

Commented:
[0-9]|[1-5][0-9]|60

Author

Commented:
Thank you Ravenpl. That works but still a bit confused. The first bracket goes 0-9, then the second and third show 10-59, and the last shows 60, am I correct?
Top Expert 2005

Commented:
Yes You correct. The | means simply OR, so there ae three patterns to mach
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.