zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Ray Andrews <rayandrews@eastlink.ca>, zsh-users@zsh.org
Subject: Re: here document within a switch fails to parse.
Date: Fri, 8 Jan 2021 18:06:19 +0000 (GMT)	[thread overview]
Message-ID: <600797233.2799876.1610129180019@mail2.virginmedia.com> (raw)
In-Reply-To: <fdff6650-85eb-fad5-a169-673d31c119fb@eastlink.ca>

> On 08 January 2021 at 17:13 Ray Andrews <rayandrews@eastlink.ca> wrote:
> function test1 ()
> {
> :<<EOC
> $(print something from a function with dollarsign)
> print something from a function redirected > /dev/stderr
> $(print something from a function both > /dev/stderr)       # This is 
> the only thing that prints.
> print something from a function
> COMMENT from a function
> echo "echo from a function"
> EOC
> }
> 
> ... not to belabor it, but why in heaven is just that one construction 
> evaluated?

You have what is effectively a double quoted expression.  The shell
evaluates any substitutions it needs to get the arguments to the
command, so it can execute it.  It needs to do that so it can end
up with a simple set of strings, "command", "command argument 1",
and so on.  At this point it doesn't care what the command actually
is.  (In particular, it does NOT think "oh, this is Ray abusing
the ":" command, so I'd better not do my usual processing".  Nobody
has got around to adding that mode to the shell yet.)

So how it does it get "command argument 1" from the expression
you've passed to it?  There are only actually two subsitutions
in that expression to be evaluated, the two $(...) expressions;
everything else will be passed to the command as is.  That
includes anything that happens to look like a command ---
remember, it's just stuff in a double quoted string at this point.

The first $(...) is evaluated.  It has no redirection, so that
argument to the "print" is substituted into the string.  You
don't actually see that, it's just part of the command argument
now.

The second $(...) is evaluated.  This time, there's a redirection,
so the argument gets sent to stderr, so you see it.  There's
no output to stdout, so what will actually be substituted into
the argument on the command line is the empty string.

pws


  reply	other threads:[~2021-01-08 18:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 15:13 Ray Andrews
2021-01-06 16:20 ` Daniel Shahaf
2021-01-06 17:17   ` Ray Andrews
2021-01-06 17:58     ` Lawrence Velázquez
2021-01-06 19:18     ` Bart Schaefer
2021-01-07  7:55       ` Ray Andrews
2021-01-07 15:32         ` Daniel Shahaf
2021-01-07 20:16           ` Ray Andrews
2021-01-08 15:27             ` Karsten Borgwaldt
2021-01-08 15:53               ` Lawrence Velázquez
2021-01-08 17:13                 ` Ray Andrews
2021-01-08 18:06                   ` Peter Stephenson [this message]
2021-01-08 19:39                     ` Ray Andrews
2021-01-08 19:56                       ` Bart Schaefer
2021-01-09  0:45                         ` Ray Andrews
2021-01-09 17:28                         ` Ray Andrews
2021-01-12 13:28             ` Daniel Shahaf
2021-01-12 14:45               ` Ray Andrews
2021-01-13 16:17                 ` Daniel Shahaf
2021-01-13 21:57                   ` Pier Paolo Grassi
2021-01-13 23:39                     ` Ray Andrews
2021-01-13 23:54                       ` Lawrence Velázquez

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=600797233.2799876.1610129180019@mail2.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@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).