for loops

Ronald S H Khoo ronald at robobar.co.uk
Sun Apr 7 22:55:34 AEST 1991


rich at pencil.cs.missouri.edu (Rich Winkel) writes:

> 	FILES=10
> 	for i in `head -$FILES /usr/dict/words`

Hee hee.  Neat hack.  I got a feeling that my boss would be very unhappy if
I used that in production code though :-)  But I like it.
 
> I guess someone's going to tell me now that 'head' isn't standard unix?

Yes, but unless you're head'ing more than one file, sed <n>q is the same
as head -n, so you could have avoided the use of that disclaimer, had
you said:

 	for i in `sed ${FILES}q /usr/dict/words`

Also, if no shell variables are involved, sed 10q is less to type than
head -10 :-)
-- 
Ronald Khoo <ronald at robobar.co.uk> +44 81 991 1142 (O) +44 71 229 7741 (H)



More information about the Comp.unix.shell mailing list