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

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-16-2009
dashing201 dashing201 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 14 October 2014, 11:02 AM EDT
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 12-16-2009
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 13 December 2014, 6:28 PM EST
Location: Zürich
Posts: 8,489
Thanks: 333
Thanked 1,050 Times in 916 Posts

Code:

while [ $var1 -lt $var2 ]

"<" is used for redirection
Sponsored Links
    #3  
Old 12-16-2009
dashing201 dashing201 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 14 October 2014, 11:02 AM EDT
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.

KUDOS
    #4  
Old 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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 03:58 AM.