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
Loop Problem namishtiwari Shell Programming and Scripting 5 07-15-2008 09:55 AM
awk and loop problem invinzin21 Shell Programming and Scripting 3 02-04-2008 09:54 PM
for loop problem namishtiwari Shell Programming and Scripting 5 01-25-2008 12:58 PM
Problem with while loop and SQL nandajk UNIX for Dummies Questions & Answers 20 05-04-2007 06:19 AM
loop Problem dhananjaysk Shell Programming and Scripting 3 03-31-2006 01:05 PM

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 08-16-2008
mdap mdap is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 12
Unhappy for loop problem

hi,

how do you create a loop command given the following requirements?

go = ( out1 out2 out3 )

for i in go
do

echo $go

done

the script aboe does not work for me.

what i want the script to do is it will echo each variable until it reaches the last variable inside go.

im assuming that the output would be somewhat like:

out1
out2
out3

thanks.
  #2 (permalink)  
Old 08-16-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Place the string between quotes and there should be no spaces around the "=" sign:

Code:
go=("out1 out2 out3")

for i in $go
do
  echo "$i"
done
  #3 (permalink)  
Old 08-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The parentheses might also need to be taken out, depending on your shell.

Code:
go="out1 out2 out3"
The for loop simply splits its arguments on whitespace.
  #4 (permalink)  
Old 08-16-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
ya era i am agree with you "(" may not work in all shell
or else you can simply try
echo "$go"|awk '{printf $1"\n"$2"\n"$3"\n"}'
provided you have less no of out
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 12:43 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