Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to deal with [] with foreach in csh

Status
Not open for further replies.

entrylevel

Technical User
Nov 29, 2001
46
CA
I have a file contains all the names that i need to create directories for,

> more list
align_c_i_fix_out_reg[9]:D.sp
add_408_40_g121:A.sp
align_c_i_fix_out_reg[10]:D.sp
align_g1851:A0.sp

in sh i can do with no problem

#!/bin/sh
for var in `cat list`
do
mkdir tmp/"$var"
done

in ksh i can do with no problem

#!/bin/ksh
for var in $(cat list_2)
do
mkdir tmp/"$var"
done

just curious how to do it in csh?

when I tried

#!/bin/csh
foreach i ("`cat list_2`")
mkdir tmp/"$i"
end

says "foreach: No match"

but I can do
> set testvar="`cat list | head -1`"

please comment, thanks.

Regards!

 
And this ?
#!/bin/csh
foreach i (`cat list_2`)
mkdir tmp/"$i"
end

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PH,

Tried what you suggested still got

foreach: No match

I think I should jump out of the mind with foreach, since I can do

> set testvar="`cat list | head -1`"

do you have a good idea on how to read from a file (each line) and assign it to a variable, that way will do it.

I know csh is not good for shell scripting, just want to know how. Thanks.

Regards!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top