From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from news.lsuc.on.ca ([142.57.1.101]) by archone.tamu.edu with SMTP id <18926>; Thu, 12 Dec 1991 19:17:31 -0600 Received: by news.lsuc.on.ca (/\==/\ Smail3.1.24.1 #24.4) id ; Thu, 12 Dec 91 20:17 EST Received: by golem.uucp (/\==/\ Smail3.1.24.1 #24.13) id ; Thu, 12 Dec 1991 19:59 -0500 To: Chris Siebenmann cc: The rc user community Subject: Re: A lighter read function In-reply-to: Your message of "Wed, 11 Dec 91 14:28:23 EST." <91Dec11.142829est.2716@hawkwind.utcs.toronto.edu> Date: Thu, 12 Dec 1991 18:58:56 -0600 Message-ID: <26539.692585936@golem.UUCP> From: "David J. Fiander" >From: Chris Siebenmann > Here is my current version of read along with a couple of functions >that it relies on: It looks pretty good. > ># A real read function, as in 'read var var var'. Returns failure ># on EOF. relies on the 'line' program. >nl=' >' >fn read { _v=() _i=() { > _v=`` $nl {line; echo $status} This is why byron added the "``ifs{}" extension, but the Plan 9 way is probably ifs=$nl { _v=`{line; echo $status}} which sets ifs for only the one command, but sets _v globally. > if (! ~ $_v(2) 0) return $_v(2); There's a small problem with this. If line sees an EOF, then it will print a newline, and exit with status 1. _v is thus set to "1", since there is nothing before the first nl. There is no $_v(2), so the ~ fails, and read returns success. I got around this by writing it as: x = `{line || echo 1^$nl^1; echo 0} Then, if line fails, we get x = (1 1) otherwise we get x = ('the line' 0) -- David J. Fiander |email [Fr., = enamel] Used attrib. in `email ink', ink |used on glass, porcelain, etc.