954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

real noob syntax question

echo "Please enter a number between 0 & 100 followed by [ENTER]:”
read NUMBER

case $NUMBER in
   -ge 0 –le 49) echo "F”;;
   -ge 50 –le 59) echo "D”;;
   -ge 60 –le 69) echo "C”;;
   -ge 70 –le 79) echo "B”;;
   -ge 80 –le 100) echo "A”
esac


its syntax error near 0 thats coming up

thanks all

towelee
Newbie Poster
2 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

1. read will receive a string, not an integer
2. use if statements, i.e. if [ $NUMBER -ge 0 ] && [ $NUMBER -le 49 ]; then echo "F"; elif [] && []; then echo "D"; elif...

DimaYasny
Posting Virtuoso
Moderator
1,777 posts since Jan 2007
Reputation Points: 183
Solved Threads: 89
 

Case labels are basically simple regex's.

So you might be able to do this

[0-4]*) echo "F”;;
   5*) echo "D”;;
   6*) echo "C”;;
   7*) echo "B”;;
   [89]*) echo "A”;;


But the if/else logic is a bit safer, and more intuitive.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You