I like here documents,

Metoo, although there may be a bias according to people's typical application domains: I often use them (on (l)unices) to spout the obscene gibberish that some external system requires:

        mysql --blah-blah <<!
        select $blah blah;
        $imbibe_rat_urine
        ...
        !

and it's a hell of a lot saner and simpler if it's all bottled up in in one place,
rather than spread all over the script.

I may not use them frequently but when I do they are a brain-saver.


I think they look better than multi-line echoes

Exactly: they are an aesthetic convenience compared with multiple 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 functions work,
as do things like:
        $ for n in 1 2 3 4 5;do cat<<EOF;done
        > $n
        > EOF
see below for why.

A quick scan of the rc source code suggests that rc won't DTRT with 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 needed. IIRC it ate temporary files and there were also a few perverse 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.  ☺

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 castigated for anomalousness.

DaveL




Reply via email to