Re^2: Line at a time scripts in csh

Maarten Litmaath maart at cs.vu.nl
Tue Jan 17 01:36:26 AEST 1989


marquez at pnet01.cts.com (Dan Castro) writes:
\maart at cs.vu.nl (Maarten Litmaath) writes:
\>foreach i ("`cat file`")        # create 1 string
\>        ..."$i"...              # avoid * and friends getting expanded
\>end

\... The script shown above didn't work on my system.

It should work, due to a csh quirk; the Bourne shell will create 1 string
containing the complete file, whereas csh processes each line seperately:

	for i in "`cat file`"
	do
		...
	done

won't do what was intended; leaving out the quotes doesn't help either.

\(Microport V/AT 286 2.3) The following did work for both the Bourne
\and c shells...

Yeah? I guess you've got a problem: portability. :-)

[ long *Bourne shell* script deleted ]

Here's my solution:

	#! /bin/awk -f
	{ print $0, $2, $1 }

Cute, not? I love it when a plan comes together.
If your UNIX version doesn't recognize the `#!' magic number:

	/bin/awk '{ print $0, $2, $1 }' $*
-- 
Lee Harvey Oswald was a patsy.        |Maarten Litmaath @ VU Amsterdam:
                       Or a superman. |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list