if statement

Ray Parrish crp at cmc.net
Thu Aug 20 20:18:35 UTC 2009


Thomas K Gamble wrote:
> On Thursday 20 August 2009 10:29:15 am Ray Parrish wrote:
>   
>> Hello,
>>
>> I am having difficulty with an if statement. Here it is -
>>
>> # load the sleep interval in seconds from the command line.
>> interval=$2;
>>     # if specified interval in seconds is less than 200 or empty, set it
>> to the default of 300 seconds
>>     if  [ $interval == "" ]
>>
>>         then
>>             interval=300; # five minutes default setting
>>             echo "interval blank";
>>     fi
>>
>> Here is the error I keep getting, no matter how I try to change the if
>> statement around -
>>
>> ray at RaysComputer:~$ ~/WebChange/UpdateWebURL.sh
>> http://finance.yahoo.com/q?s=MSFT
>> /home/ray/WebChange/UpdateWebURL.sh: line 25: [: ==: unary operator
>> expected
>>
>> I actually want to check to see if interval is blank or less than 200,
>> but I can't seem to get that to work.
>>
>> This happens with a single "=" as well. What am I doing wrong here?
>>
>> Thanks for any help you can be. Later, Ray Parrish
>>
>>
>>
>>
>> After reading your message more closely I think what you want is:
>>
>> 	if [ -z "$interval" ] || [ $interval -lt "200" ]
>>
>>     
>> This works perfectly, thank you. I have another test to perform to 
>> test $1 and will apply what I've learned here to the next one.
>>
>>>> This will test for the null condition, then the less than 200 
>>>> condition. May I also suggest doing a google search for "Advanced 
>>>> Bash Shell Scripting
>>>> Guide pdf" and downloading it. A useful free resource.
>>> Thanks for the tip on the bash scripting guide, I've been consulting 
>>> some of the others, and they do not have very good indexing to 
>>> syntax conventions for the most part.
>>>
>>> Later, Ray Parrish
>>>
>>> The Future of Technology.
>>>  http://www.rayslinks.com/The%20Future%20of%20Technology.html
>>>  Ray's Links, a variety of links to usefull things, and articles by Ray.
>>>  http://www.rayslinks.com
>>>  Writings of "The" Schizophrenic, what it's like to be a schizo, and 
>>> other
>>>  things, including my poetry.
>>>  http://www.writingsoftheschizophrenic.com
>>>




More information about the ubuntu-users mailing list