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
foreach loop ROOZ Shell Programming and Scripting 3 06-05-2008 03:20 PM
using foreach loop sam4now Shell Programming and Scripting 6 04-26-2008 11:22 AM
foreach loop abch624 Shell Programming and Scripting 1 03-19-2008 09:34 PM
Foreach loop haze21 Shell Programming and Scripting 4 11-16-2007 03:11 AM
foreach loop question clipski UNIX for Dummies Questions & Answers 7 12-22-2005 01:28 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 06-03-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
foreach loop + 2 variables

In a foreach loop, is it possible for the loop to go through 2 arguments instead of one

i.e. instead of foreach i (do stuff for i), we have foreach i j(do stuff for i; do stuff for j)

I am working under BASH and TCSH shell environments

cheers
  #2 (permalink)  
Old 06-03-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
You can do that with while:

Code:
while read i j; do
  stuff with i
  stuff with j
done <<HERE
firsti firstj
secondi secondj can have several fields actually
thirdi thirdj -- it splits on whitespace
fourthi fourthj; but only as many as necessary
fifthi fifthj ... and the remainder is unsplit
HERE
It's not exactly what you asked for, but hopefully close enough.
  #3 (permalink)  
Old 06-03-2008
JamesGoh JamesGoh is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 89
thanks heaps, will have a go and get back to you
  #4 (permalink)  
Old 06-04-2008
Wolja's Avatar
Wolja Wolja is offline
Registered User
  
 

Join Date: Feb 2002
Posts: 15
Quote:
Originally Posted by era View Post
You can do that with while:

Code:
while read i j; do
  stuff with i
  stuff with j
done <<HERE
firsti firstj
secondi secondj can have several fields actually
thirdi thirdj -- it splits on whitespace
fourthi fourthj; but only as many as necessary
fifthi fifthj ... and the remainder is unsplit
HERE
It's not exactly what you asked for, but hopefully close enough.
God I wish I'd read this three days ago

Ta very useful.
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 10:07 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