Re: Case statement

From: Ed Morton (morton_at_lsupcaemnt.com)
Date: 05/31/05


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.



Relevant Pages

  • Re: Evangelist predicts US town will be smote by God
    ... >William wrote: ... Ask any leading Christian denomination, ... >> cult whether we should interpret scripture with the help of the Holy ... >mainstream Christians not to trust any hint of supernatural guidance in ...
    (uk.religion.christian)
  • Re: Re: Re: Veritas [LONG - Sorry!]
    ... Most humans don't interpret "Stop being such an asshole" as an order. ... William December Starr ...
    (rec.arts.sf.written)