Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Non-forking command substitution
- X-seq: zsh-workers 51107
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Non-forking command substitution
- Date: Tue, 6 Dec 2022 16:46:24 -0800
- Archived-at: <https://zsh.org/workers/51107>
- In-reply-to: <21586f92-9a78-419c-84e5-f203a6f069b6@app.fastmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <54bcd6dd-e589-4696-f042-1155b78df9d2@eastlink.ca> <CAN=4vMp2r4Syu-CuF=gxed5om9JQ+NDQm6LvNZRBE4d5a4v1xw@mail.gmail.com> <819c9630-f315-8b1c-cb52-3d3ae8de2d5c@eastlink.ca> <CAN=4vMqKXudgwwQAPNzJ0OymhYWwPWu+ec+LyiVK2nhDP1jbeg@mail.gmail.com> <7eadf163-da34-d90b-61ce-b527fb75b597@eastlink.ca> <CAN=4vMq7=BGygpKU4ed_b33tdE0NGoCALZdaF10hz0co4zqksQ@mail.gmail.com> <37b2456f-0459-4b85-74d1-bb380715e2ed@eastlink.ca> <CAN=4vMp_LqvioJE_uW2_CwJ7CKL2dVwGn-6LMonPf_5pfngkzA@mail.gmail.com> <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@xxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author