From mboxrd@z Thu Jan 1 00:00:00 1970 From: rogpeppe@gmail.com (roger peppe) Date: Mon, 4 Apr 2011 10:26:39 +0100 Subject: [9fans] Making read(1) an rc(1) builtin? In-Reply-To: <5ddd9deccbea5e8556dfc0c228b63311@ladd.quanstro.net> References: <86fwpz55nj.fsf@cmarib.ramside> <257867.782e4d7b.wsc0.mx@tumtum.plumbweb.net> <5ddd9deccbea5e8556dfc0c228b63311@ladd.quanstro.net> Message-ID: Topicbox-Message-UUID: c8061628-ead6-11e9-9d60-3106f5b1d025 On 4 April 2011 03:53, erik quanstrom wrote: > i think this is what you want > > ? ? ? ?for(line in `{ifs=$nl cat}){...} no, because that only sets ifs for the cat command, not for the `{} construct. ifs=$nl for (line in `{cat}) { ... } is perhaps what you meant to say. > but i have no idea why one would avoid the read > idiom. ?for large input, forking off a read for each > line keeps the memory footprint O(1). FWIW, i think that avoiding a read(1) loop is perfectly reasonable thing to want to do. a quick test i measured that calling read in shell loop was about 100 times slower than using `{}, and about 500 times slower than using awk to read the lines. in general, unless it was truly necessary, i would try to use awk or sed rather than use read(1) in a loop when i was going to deal with significantly sized input. when i've needed a "-n safe" version of echo in the past, i've used something like this: fn myecho {echo -n $"* ^ ' '}