WHILE LOOP CONDITION CHECK | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

WHILE LOOP CONDITION CHECK

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-16-2009
dashing201 dashing201 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 13 January 2015, 5:42 AM EST
Posts: 75
Thanks: 11
Thanked 0 Times in 0 Posts
WHILE LOOP CONDITION CHECK

Hello

I want to compare values of two variables as CHECK condition in a while loop.

eg:


Code:
var1=0 
var2=10   
while [ $var1 < $var2 ] 
do   
    echo " $var1 "
    var1=`expr $var1 + 1`
done

However this is giving error.How to do it in a proper manner?

Thanks.
Sponsored Links
    #2  
Old Unix and Linux 12-16-2009
Scott's Unix or Linux Image
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 6 March 2015, 2:19 PM EST
Location: Zürich
Posts: 8,530
Thanks: 336
Thanked 1,065 Times in 928 Posts

Code:

while [ $var1 -lt $var2 ]

"<" is used for redirection
Sponsored Links
    #3  
Old Unix and Linux 12-16-2009
dashing201 dashing201 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 13 January 2015, 5:42 AM EST
Posts: 75
Thanks: 11
Thanked 0 Times in 0 Posts
Thanks Buddy...
I was trying it on CYGWIN. it was giving some error.However I tried it on unix , it is working fine.

KUDOSUnix or Linux Image
    #4  
Old Unix and Linux 12-16-2009
ichigo ichigo is offline
Ghostdog (Read Only)
 
Join Date: Dec 2009
Last Activity: 19 December 2009, 6:21 AM EST
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
var1=0
var2=10
gawk -v v1="$var1" -v v2="$var2" 'BEGIN{
    while(v1 < v2){
        print v1
        v1++
    }
} '

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
csh if loop variable condition check peroblem vasanth.vadalur Shell Programming and Scripting 0 11-06-2009 08:43 AM
using flag inside a for loop to check condition codeman007 Shell Programming and Scripting 4 01-13-2009 04:30 PM
how can i put the condition in for loop for the below. mail2sant Shell Programming and Scripting 1 04-28-2008 05:49 AM
What condition to be put in the while loop? nehaquick UNIX for Dummies Questions & Answers 1 02-15-2008 04:06 PM
End of loop condition required??? skyineyes Shell Programming and Scripting 4 07-16-2007 04:10 AM



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