Re: Case statement
From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/31/05
- Next message: Ed Morton: "Re: using grep to find IP address..."
- Previous message: Paulie: "Executing command in Shell"
- In reply to: William: "Re: Case statement"
- Next in thread: Bill Marcum: "Re: Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 May 2005 11:35:28 -0500
William wrote:
> <joe@invalid.address> wrote:
>
>
>>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
>
>
> Apologies for asking another daft question :-(
>
> If a user were to input say.
>
> Enter a value: 1 2 3 4
>
> Is there any way of catching that to produce an error? with the above being
> considered.
Is the problem that you only expect 1 value? If so just test for the
number of parameters being other than 1 before you get to the above case
statment:
if [ $# -ne 1 ]
then
echo "bad, bad,...."
exit 1
fi
case ...
Regards,
Ed.
- Next message: Ed Morton: "Re: using grep to find IP address..."
- Previous message: Paulie: "Executing command in Shell"
- In reply to: William: "Re: Case statement"
- Next in thread: Bill Marcum: "Re: Case statement"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|