The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-16-2008
ganapati's Avatar
Registered User
 

Join Date: Jul 2006
Posts: 114
Exclamation Problem with foreach loop

Hi All,

Is there any problem with the below 'foreach' loop?
foreach risk_factor ($(cat "$rf_list"))

where "rf_list=$SCRIPT/Utility/rflist.txt "

I'm wondering, it is throwing below error message:
syntax error at line 34: `(' unexpected

Any idea/suggestions ?

Thanks in advance / Mysore Ganapati.

Last edited by ganapati; 09-16-2008 at 05:53 AM. Reason: missing one line
Reply With Quote
Forum Sponsor
  #2  
Old 09-16-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
Using cat is redundant try this:

Code:
while read risk_factor; do
  # do something with "$risk_factor"
done < "$rf_list"
Regards
Reply With Quote
  #3  
Old 09-16-2008
ganapati's Avatar
Registered User
 

Join Date: Jul 2006
Posts: 114
Thanks Franklin,

It worked, but what could be the problem with foreach loop?
Can you clear my doubt please?

Thanks and Regards / Mysore Ganapati
Reply With Quote
  #4  
Old 09-16-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
AFAIK for each loops is used in csh/tcsh scripts but I'm not familiar with it.

Regards
Reply With Quote
  #5  
Old 09-18-2008
otheus's Avatar
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 605
you are mixing shells here. $() is understood by bash/ksh, while foreach is csh/zsh specific. Which shell are you actually using?
Reply With Quote
  #6  
Old 09-19-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The error message would indicate Bourne-compatible (sh/ksh/bash -- zsh belongs to this group, too, although it does feature a foreach command, similar to csh's).
Reply With Quote
  #7  
Old 09-19-2008
ganapati's Avatar
Registered User
 

Join Date: Jul 2006
Posts: 114
Hi Otheus,

I'm using 'csh'. Dont know exactly whether I'm mixing the shells or not!

Cheers ~~ / Mysore Ganapati
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0