From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Jett Husher <jetthusher@pm.me>
Cc: zsh-workers@zsh.org
Subject: Re: What does REDIRF_FROM_HEREDOC flag represent?
Date: Thu, 21 Oct 2021 14:39:15 +0000 [thread overview]
Message-ID: <20211021143915.GD16034@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <UNGkzCHSmvNpdTsMVzHx7jyFHTT7l5Q2e_dT34ii2CHlMkkGkta1DEACUzRXldhBDR1aLOdMnFp9B4IO_0PQYswtcqjyDwkQEVdp3PwZqvQ=@pm.me>
Jett Husher wrote on Thu, Oct 21, 2021 at 09:53:42 +0000:
> Good day!
>
> I was peeking at the source code
Welcome :)
> and found REDIRF_FROM_HEREDOC flag. The comments say that it's for a
> here-string that came from a here-document but I'm still not clear how
> this looks exactly.
A here-string is this thing:
item(tt(<<<) var(word))(
Perform shell expansion on var(word) and pass the result
to standard input. This is known as a em(here-string).
Compare the use of var(word) in here-documents above, where var(word)
does not undergo shell expansion.
)
Example:
% nl -ba <<< $'foo\nbar'
1 foo
2 bar
%
> Is it that every line in heredoc is a here-string?
No.
> I've tried to read the part in parser.c where this flag is being set,
> but couldn't make sense of it since I'm not at all acquainted with C
> or the codebase as a whole.
I think what happens is this:
- After parsing, a here-doc is represented as a here-string with
REDIRF_FROM_HEREDOC set
- text.c looks for that bit and does the reverse transformation, so
stuff like
.
f() { foo <<< lorem; bar <<'EOF'
ipsum
EOF
}
.
gets emitted by `which f` using the same type as input redirections as
it used when the shell first lexed/parsed it.
- exec.c appends a newline to here-strings' data before passing it to
commands; see:
.
% xxd <<<foo
00000000: 666f 6f0a foo.
- There are no other mentions of REDIRF_FROM_HEREDOC.
It did help that I already knew what each file does in general, but
yeah, I don't have access to zsh-with-comments.git either ☹
Cheers,
Daniel
> Would very much appreciate the explanation.
>
> - Jett
>
next prev parent reply other threads:[~2021-10-21 14:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-21 9:53 Jett Husher
2021-10-21 14:39 ` Daniel Shahaf [this message]
[not found] ` <vBtfA3xVArPp-qWVYvqO2koSzHro1ms6um1SMPrWwJSp-luOAzAkWH2xx7FAxaPw8IWt1uQw3PiNd0yhOfXRAMGRgSGlscm23N0CnMY1oKI=@pm.me>
2021-10-22 4:42 ` Jett Husher
2021-10-25 19:30 ` Daniel Shahaf
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=20211021143915.GD16034@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=jetthusher@pm.me \
--cc=zsh-workers@zsh.org \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
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).