From mboxrd@z Thu Jan 1 00:00:00 1970 Mime-Version: 1.0 (Apple Message framework v752.3) In-Reply-To: References: Content-Type: text/plain; charset=UTF-8; delsp=yes; format=flowed Message-Id: <40711DDA-D0EC-496B-BB91-9132B3ADBD78@mac.com> Content-Transfer-Encoding: quoted-printable From: dave.l@mac.com Subject: Re: [9fans] late to the party - Here docs Date: Wed, 7 Nov 2007 16:41:09 +0000 To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Topicbox-Message-UUID: edcaec20-ead2-11e9-9d60-3106f5b1d025 >> I like here documents, Metoo, although there may be a bias according to people's typical =20 application domains: I often use them (on (l)unices) to spout the obscene gibberish that =20 some external system requires: mysql --blah-blah <> I think they look better than multi-line echoes Exactly: they are an aesthetic convenience compared with multiple =20 echo invocations but so are quotes compared with multiple backslashes. >> though it is annoying they can't be used in fn definitions. That's a bug which could be fixed ... > i was thinking about this topic again the other day during an > idle moment. here documents are part of the parsing routine. > but they don't end up in rc's machine language. Does this mean they don't work in loops too? Sadly, I have to nerdishly play sh's advocate: I just tested a recent ksh and bash and, as expected, heredocs in =20 functions work, as do things like: $ for n in 1 2 3 4 5;do cat< $n > EOF see below for why. A quick scan of the rc source code suggests that rc won't DTRT with =20 an analogous construct: can someone with a running plan9 or p9p please confirm this as a matter of academic interest? It's non-trivial (but not hard) to implement correctly: the old Bourne shell, and thus, presumably, it's successors, DidTRT: store the text of the here documents verbatim when they are parsed then spit the substituted text into a (new) tempfile every time it's =20 needed. IIRC it ate temporary files and there were also a few perverse =20 boundary cases where it would break or lose track of it's temp files or leave them lying around, but so what?. Trivial aside: sh also did `...` in here docs, as do it's successors. > they really are anomolous critters. they need to be taken out > back and shot. =E2=98=BA Anomalous in use or in implementation? Personally I think they are fine, but their current implementation may need care and feeding. If punishment is desired, may I suggest that the implementor be =20 castigated for anomalousness. DaveL