From: Paul Haahr <haahr@mv.us.adobe.com>
To: Alan Watson <alan@oldp.astro.wisc.edu>
Cc: rc mailing list <rc@hawkwind.utcs.toronto.edu>
Subject: Re: Here documents
Date: Thu, 17 Dec 1992 12:12:51 -0500 [thread overview]
Message-ID: <9212171712.AA04914@utopia.mv.us.adobe.com> (raw)
> 1. Can someone provide a more definitive definition of the
> source of here documents.
here documents are always read from the same place as where commands are
read. they are also read at parse time, not execution time. this is done
to support here docs in functions and loops, which i believe are not
supported by td's rc. (use rc -nx to explore what's going on: heredocs get
turned into here strings.)
;; rc -nx
; cat << EOF
hello, $USER
EOF
cat <<<'hello, '^$^USER^'
'
;
> 2. Should a here document be read from rc's stdin, rather than the
> source of its commands? Would this break any existing scripts?
> This would allow example [3] to work.
no, that's what redirection, pipes, and normal standard input processing do.
it would break just about every script.
> 3. Should a here document be read from a command's stdin,
> rather than the shell input? Would this break any existing scripts?
> This would allow example [2] to work.
no, for the same reasons.
----
as to your examples, i don't see why you're using here docs:
> [2] ; { echo '$foo' ; echo EOF } | cat <<EOF
> [3] ; { echo '$foo' ; echo EOF } | rc -c 'cat <<EOF'
why not
echo $foo | cat
or (if you insist on using heredocs)
cat << EOF
$foo
EOF
both of which seems to do what you want.
> [4] ; { echo 'cat <<EOF' ; echo '$foo' ; echo EOF } | rc
here you're doing exactly what rc is not supposed to do: parsing the same
data twice, in this case by two separate shells. (you could actually do
something similar with eval, but the idea is the same.)
it seems that you want to take the output of some program, containing
references to shell variables, expanded by the heredoc machinery. that does
seem like an appropriate use of a second shell, in which case example 4 is
the way to go.
> I am intrigued that such subtleties exist in an apparently
> straightforward feature of the language.
heredocs don't fit naturally into the model of the rest of the shell, but
are so useful as to warrant an exception. i think byron's solution (here
strings and conversion at parse time) is elegant and clever, and, when
understood, makes the answers to ``what if?'' questions obvious.
next reply other threads:[~1992-12-17 17:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-12-17 17:12 Paul Haahr [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-12-17 19:19 Byron Rakitzis
1992-12-17 18:29 Alan Watson
1992-12-18 3:08 ` Scott Merrilees
1992-12-17 14:10 Alan Watson
1992-12-17 9:00 Alan Watson
1992-12-08 17:17 raymondc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9212171712.AA04914@utopia.mv.us.adobe.com \
--to=haahr@mv.us.adobe.com \
--cc=alan@oldp.astro.wisc.edu \
--cc=rc@hawkwind.utcs.toronto.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).