Re: Case statement

joe_at_invalid.address
Date: 05/31/05


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



Relevant Pages

  • Case statement
    ... 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. ...
    (comp.unix.shell)
  • TIP #185: Null Handling
    ... nulls, and command modifications for manipulating them. ... Tcl deals with strings, the universal medium for representing data. ... is know and it is an empty string, but if a respondent forgets to give ...
    (comp.lang.tcl)
  • Re: Determine how Word was launched
    ... inspect the command line used to launch Word. ... Private Declare Function GetCommandLineA Lib "kernel32" As Long ... Public Function GetCommandLineAs String ... Dim lngCmdLinePtr As Long ...
    (microsoft.public.office.developer.vba)
  • Re: Class.getMethod in classs static initializer block
    ... I just wanted to add that I had some similar code for a "command line server" project. ... static private final boolean DEBUG = true; ... {public ReturnCode runCommand(String s) ... public ReturnCode parseLine(String line) ...
    (comp.lang.java.programmer)
  • Re: New "base document" available
    ... How to go about retrieving command line parameters? ... the command line arguments (and environment variables) ... Keyword and positional parameters can be mixed in the same command line. ... clp-name points to a string containing "P1" ...
    (comp.lang.cobol)