The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 07: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 06:01 PM
Unix shell scripting to find latest file having timestamp embedded... kaushik25 AIX 2 08-06-2007 10:42 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
UNIX find by time scripting budrito UNIX for Advanced & Expert Users 1 10-08-2004 05:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-26-2007
pinky pinky is offline
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
  #2 (permalink)  
Old 07-26-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

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
  #3 (permalink)  
Old 07-27-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Code:
echo 20  | awk '{ if ( 20 <= $0 && $0 <= 30 ) { print "in-between" } else { print "out-of-range" } }'

Last edited by matrixmadhan; 07-27-2007 at 01:25 AM.. Reason: range specification
  #4 (permalink)  
Old 07-27-2007
pinky pinky is offline
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
  #5 (permalink)  
Old 07-27-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

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.
  #6 (permalink)  
Old 07-27-2007
pinky pinky is offline
Registered User
  
 

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

Pinky
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0