zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Non-forking command substitution
Date: Tue, 6 Dec 2022 16:46:24 -0800	[thread overview]
Message-ID: <CAH+w=7YE-RCGE31PH7H117Eq3tRpAajN7Xf21qDPPL7nzT9Brg@mail.gmail.com> (raw)
In-Reply-To: <21586f92-9a78-419c-84e5-f203a6f069b6@app.fastmail.com>

Redirecting to zsh-workers.

On Tue, Dec 6, 2022 at 3:54 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Tue, Dec 6, 2022, at 1:55 PM, Roman Perepelitsa wrote:
> > That said, it's totally possible to extend zsh with something like $[
> > ... ] which would work like $( ... ) but without forking. It would run
> > the commands in another thread within the same process.
>
> FWIW, ksh has a ${ list;} construct that avoids a subshell:

The "when followed by a space ${ starts a command, otherwise it's a
parameter reference" is a bit odd, but I guess not odder than some of
the things we do.

Based on some random poking at ksh93, this construct does two things:
1. Switches from fork-to-the-right (bash, older sh) behavior to
fork-to-the-left (zsh) behavior for pipes, so the rightmost part of a
pipeline may run in the current shell.
2. If the rightmost thing is a builtin, captures/substitutes its
output instead of printing it to stdout, otherwise acts exactly like
$(...)

Neither of those things actually requires a separate thread, though it
does require some engineering down in the guts of builtin commands to
replace simple stdio handling.

It'd be interesting to know how ksh93 handles the ^Z/fg issues with
left-forking that were recounted in recent -workers discussion.


           reply	other threads:[~2022-12-07  0:47 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <21586f92-9a78-419c-84e5-f203a6f069b6@app.fastmail.com>]

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='CAH+w=7YE-RCGE31PH7H117Eq3tRpAajN7Xf21qDPPL7nzT9Brg@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --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).