![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| If Statement Problem.. | LinuxRacr | Shell Programming and Scripting | 2 | 02-26-2008 08:47 PM |
| problem with if statement equality | cleansing_flame | Shell Programming and Scripting | 1 | 02-12-2008 06:57 AM |
| Case statement problem | gzs553 | UNIX for Advanced & Expert Users | 6 | 11-14-2006 12:24 PM |
| problem with an IF statement | hcclnoodles | Shell Programming and Scripting | 2 | 04-17-2003 07:53 AM |
| if statement problem | coughlin74 | UNIX for Dummies Questions & Answers | 1 | 09-27-2001 01:31 PM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
if statement problem
hi all. i just have a very small problem. i have a menu of 7 choices. i want an if statement so that if the user chooses anything except inside the 1 to 7 range, i can handle the error for it.
i tried this: if [ $choice -ne [1-7] ] then ....... fi (but it dont work) ...any suggestions? thanks all in advance |
| Forum Sponsor | ||
|
|
|
|||
|
LHS of "if" must be quoted.
Hi djt !
One of the reasons why your script does not work is that the left side MUST be in quotes, eg: Code:
if [ "$number" = "1" ]; then
echo "Number equals 1"
else
echo "Number does not equal 1"
fi
Hope that was helpful Regards Graham |
|
|||
|
Testing a range of values
Hi again djt !!
Try this one, this idea addresses the RH-side of the equation, namely: ranges of values: Code:
read character
case $character in
# Check for letters
[a-z] | [A-Z] ) echo "Alpha range i[a-z]: You typed the letter $character"
;;
# Check for digits
[0-9] ) echo "Numeric range: 0-9: You typed the digit $character"
;;
# Check for anything else
* ) echo "You did not type a letter or a digit"
esac
Again, I hope this is usefull! Rergards GrahamB |
|
|||
|
"-ne" is an operator to compare integer values (for being not equal). "[-7]" is a string, not an Int, this is why the test failed.
How to solve your task better has already been explained. bakunin |
|||
| Google UNIX.COM |