Line at a time scripts in csh

Geoff Rimmer geoff at warwick.UUCP
Tue Jan 17 10:40:51 AEST 1989


In article <4116 at paris.ics.uci.edu> posert at bonnie.ics.uci.edu (Bob Posert) writes:
>
>I have a file with two words on each line, and want to
>process them in a shell script, but can't figure out
>how to get *the entire line* into a variable.
>
>I tried:
>	foreach i (`cat file`)
>	#misc processing
>	end
>but i was set to each word, not line.
>

If you do

	foreach i ("`cat file`")
	#misc processing
	end

you will get the whole line.  However, when I tried this just now, I
realised that if there are any wild cards (?,*,[,]) then it gives the
strange error message 

	end: No match

when it gets to the line containing the ? or whatever.  Can anyone
explan this one?

>Then I tried the same thing, but adding quotes at the beginning and
>end of every line in the input file.  Basically the same thing happened,
>even though from the prompt,
>	foreach i ("One Two")
>	echo $i
>	end
>echoed the words on the same line.

I suppose when csh interprets the output of the `...` , it ignores the
quotes, but I have no idea why it should do so!!

Way back in my first year (and most of the second) I was there slaving
away at sorting out which quotes to use in csh/sh and when or not to
use a backslash etc, and I got so fed up, that I haven't written any
scripts since (except for the simplest type) and now everything is in C.  
OK, it takes a lot longer to write, but it's a lot faster, it's more
reliable, and a lot more powerful!

>   Bob Posert
>   I'm: posert at bonnie.ics.uci.edu or {sdcsvax|ucbvax}!ucivax!bonnie!posert 

Geoff


	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, England.
			geoff at uk.ac.warwick.emerald

	"It just goes to show, if you want something doing properly,
	it's best not to drink 16 pints of lager beforehand."
		- Filthy Rich and Catflap, 1986.
	------------------------------------------------------------



More information about the Comp.unix.questions mailing list