The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need your Help on Unix Shell Scripting......... vinayraj UNIX for Advanced & Expert Users 5 02-08-2008 03:00 AM
Loop till you find a string in a fine <-- Need Help New to Unix Scripting mrehman UNIX for Dummies Questions & Answers 1 01-30-2008 02:01 PM
Unix shell scripting to find latest file having timestamp embedded... kaushik25 AIX 2 08-06-2007 07:42 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
UNIX find by time scripting budrito UNIX for Advanced & Expert Users 1 10-08-2004 02:19 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
How to find whenther given value is in betwwen min and Max in unix shell scripting

Hi

I wanted to write a shell script with an if condition

Example
MinValue=10
MaxValue=30
logvalue = some integer value that script reads from the command line arguement
I wanted to check whether log value greater than or equal to10 and less than equal to 30
and proceed with the rest of hte code only if logValue is between or equal to the MinValue and MaxVlaue

If condition should work like this in unix shell scripting

if(MinValue<=logValue<=MaxValue)
Thanks in advance for all the help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-26-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
#!/bin/ksh
typeset -i MinValue=10
typeset -i MaxValue=30
typeset -i LogValue
echo 'Enter log value:'
read LogValue
if [ ${LogValue} -ge ${MinValue} -a ${LogValue} -le ${MaxValue} ]; then
  echo 'Found in between'
fi
Reply With Quote
  #3 (permalink)  
Old 07-26-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
Code:
echo 20  | awk '{ if ( 20 <= $0 && $0 <= 30 ) { print "in-between" } else { print "out-of-range" } }'

Last edited by matrixmadhan; 07-26-2007 at 10:25 PM. Reason: range specification
Reply With Quote
  #4 (permalink)  
Old 07-27-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
Thanks for the solution
It worked
I am just wondering whether the ; at the end of if (if [ ];then ) is necessary or notthe reason why I was asking is it worked with out ; and with ; so just wondering is there anything that I am missing if I don't keep the ; at the end of if

Is there any difference between

if [ ];then

fi
and

if [ ]
then

fi



Thanks in advance
Pinky
Reply With Quote
  #5 (permalink)  
Old 07-27-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
The simicolon ';' is used in korn shell as a command separator.

The reason for having '; then' is to save space and have fewer lines in the shell.
Reply With Quote
  #6 (permalink)  
Old 07-27-2007
Registered User
 

Join Date: Jul 2007
Posts: 33
Thanks
That's really useful info I appreciate it

Pinky
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0