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 > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem in For Loop The Observer Shell Programming and Scripting 2 05-28-2008 02:43 AM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 12:58 PM
loop problem maskot Shell Programming and Scripting 1 05-25-2007 04:10 AM
Problem with for loop/sed ? chiru_h Shell Programming and Scripting 2 08-27-2006 11:55 AM
problem with while loop mridula High Level Programming 1 12-11-2005 11:44 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 03-31-2006
dhananjaysk dhananjaysk is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 35
loop Problem

Hi all ,

I am having problem related to FOR loop

for i in [1..9]
do
echo $i
done

Noew the above code should give me result as
1
2
--- upto
9

But instead it gives me result as 1..9.

Please Help ..
  #2 (permalink)  
Old 03-31-2006
Igal Malka Igal Malka is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 12
Quote:
Originally Posted by dhananjaysk
Hi all ,

I am having problem related to FOR loop

for i in [1..9]
do
echo $i
done

Noew the above code should give me result as
1
2
--- upto
9

But instead it gives me result as 1..9.

Please Help ..

Hi,

Your problem is that you are not running any loop ....., you just set the string [1..9] into i and print it to the screen,
For what you want to do u need the following:

for (( i = 0 ; i <= 9; i++ ))
do
echo $i
done
  #3 (permalink)  
Old 03-31-2006
Igal Malka Igal Malka is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 12
Short explaination

When you use:

for x in 1 2 3 4

It takes the first param and set it to x,
after that it runs into 2nd param and so on till it finish read all params.
At yours case u wrote

for i in [1..9] - it act like [1..9] is the first param so it set the whole string into i, and since there is nothing after [1..9] it finish the loop after one run.

in case u insist to ust the "for i in ...." format you must enter the values like that:
1 2 3 4 5 6 7 8 9
or to create a list file containing all the params u want to run
and than u can write:
for i in $file
  #4 (permalink)  
Old 03-31-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Quote:
Originally Posted by Igal Malka
Hi,

Your problem is that you are not running any loop ....., you just set the string [1..9] into i and print it to the screen,
For what you want to do u need the following:

for (( i = 0 ; i <= 9; i++ ))
do
echo $i
done
what shell is that? Looks like bash.

Code:
#!/bin/ksh

typeset -i i=1
while (( i <= 9 ))
do
   echo "${i}"
   (( i += 1 ))
done
Sponsored Links
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 01:58 AM.


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