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
otheus
September 18, 2008, 3:58pm
5
you are mixing shells here. $() is understood by bash/ksh, while foreach is csh/zsh specific. Which shell are you actually using?
era
September 19, 2008, 3:29am
6
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
otheus
September 20, 2008, 7:56am
8
Don't use $( ... ). Instead use ` ... `