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.

Using cat is redundant try this:

while read risk_factor; do
  # do something with "$risk_factor"
done < "$rf_list"

Regards

Thanks Franklin,

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

Thanks and Regards / Mysore Ganapati

AFAIK for each loops is used in csh/tcsh scripts but I'm not familiar with it.

Regards

you are mixing shells here. $() is understood by bash/ksh, while foreach is csh/zsh specific. Which shell are you actually using?

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).

Hi Otheus,

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

Cheers ~~ / Mysore Ganapati

Don't use $( ... ). Instead use ` ... `