Re: Case statement
From: Bill Marcum (bmarcum_at_iglou.com.urgent)
Date: 05/31/05
- Next message: Bill Marcum: "Re: How to read text from a file in shell scripting"
- Previous message: balgach_at_gmail.com: "using grep to find IP address..."
- In reply to: William: "Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 May 2005 08:25:31 -0400
On Tue, 31 May 2005 12:04:48 +0000 (UTC), William
<fred@nosmapherethankyou.com> wrote:
> Hi,
>
> 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?
>
The [x-y] type of expression is strictly for matching characters, not
numbers. To match a range like 100-60000 in a case statement, you would
write something like
1[0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-5][0-9][0-9][0-9][0-9]|60000)
It might be simpler to use an if statement instead:
if [ "$VARIABLE" -ge 100 ] && [ "$VARIABLE" -le 60000 ]
-- Depend on the rabbit's foot if you will, but remember, it didn't help the rabbit. -- R.E. Shay
- Next message: Bill Marcum: "Re: How to read text from a file in shell scripting"
- Previous message: balgach_at_gmail.com: "using grep to find IP address..."
- In reply to: William: "Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|