Re: Case statement
joe_at_invalid.address
Date: 05/31/05
- Next message: Sun Xun: "Re: How to read text from a file in shell scripting"
- Previous message: William: "Re: Case statement"
- In reply to: William: "Case statement"
- Next in thread: William: "Re: Case statement"
- Reply: William: "Re: Case statement"
- Reply: William: "Re: Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 31 May 2005 09:54:25 -0500
"William" <fred@nosmapherethankyou.com> writes:
> I'm a bit stuck with the below case statement, I'm looking at taking
> input from a user using read command, then evaluating this string to
> see if it is either within a certain numeric range
> i.e. 100-60000. However when I try to specify a range it's not
> working. If I input 100, I get something else returned, I'm quite
> new to shell scripting and I guess I've not written the numeric
> range correctly?
>
> VARIABLE=
> while [ -z $VARIABLE ]
> do
> echo "Enter a Value: \c"
> read VARIABLE
> done
>
> case $VARIABLE
> in
> [100-60000])
case blocks don't work like that. The cases match string patterns, but
don't interpret them. You want to first ensure that the input is
numeric, and then test for the range. for example
case $1 in
*[!0-9]*) echo Error, input is not numeric
;;
*) if [ "$1" -ge 100 -a "$1" -le 6000 ];then
echo input is between 100 and 6000
else
echo input is not between 100 and 6000
fi
;;
esac
Joe
- Next message: Sun Xun: "Re: How to read text from a file in shell scripting"
- Previous message: William: "Re: Case statement"
- In reply to: William: "Case statement"
- Next in thread: William: "Re: Case statement"
- Reply: William: "Re: Case statement"
- Reply: William: "Re: Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|