mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-06-10 18:58:03 +02:00
52476 + cf. 52479: more FAQs about nofork substitution
This commit is contained in:
parent
0459cc2eaf
commit
0fccdf0d57
2 changed files with 40 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
2024-01-24 Bart Schaefer <schaefer@zsh.org>
|
2024-01-24 Bart Schaefer <schaefer@zsh.org>
|
||||||
|
|
||||||
|
* 52476 + cf. 52479: Etc/FAQ.yo: more about nofork substitution
|
||||||
|
|
||||||
* 52477: Src/Modules/curses.c: fix "zcurses mouse delay ..."
|
* 52477: Src/Modules/curses.c: fix "zcurses mouse delay ..."
|
||||||
|
|
||||||
* 52473: Doc/Zsh/mod_zutil.yo, Src/Modules/zutil.c: zstyle -q
|
* 52473: Doc/Zsh/mod_zutil.yo, Src/Modules/zutil.c: zstyle -q
|
||||||
|
|
38
Etc/FAQ.yo
38
Etc/FAQ.yo
|
@ -1067,6 +1067,44 @@ label(211)
|
||||||
quoted, that is, included in a quoted string or prefixed by backslash.
|
quoted, that is, included in a quoted string or prefixed by backslash.
|
||||||
These substitutions first become usable after zsh 5.9.
|
These substitutions first become usable after zsh 5.9.
|
||||||
|
|
||||||
|
sect(Comparisons of forking and non-forking command substitution)
|
||||||
|
|
||||||
|
mytt(${ command }) and variants may change the caller's options by using
|
||||||
|
mytt(setopt) and may modify the caller's local parameters, including the
|
||||||
|
positional parameters mytt($1), mytt($2), etc., via both assignments and
|
||||||
|
mytt(set -- pos1 pos2 etc). Nothing that happens within mytt($(command))
|
||||||
|
affects the caller.
|
||||||
|
|
||||||
|
mytt($(command)) removes trailing newlines from the output of mytt(command)
|
||||||
|
when substituting, whereas mytt(${ command }) and its variants do not.
|
||||||
|
The latter is consistent with mytt(${|...}) from mksh but differs from
|
||||||
|
bash and ksh, so in emulation modes, newlines are stripped from command
|
||||||
|
output (not from mytt(REPLY) assignments).
|
||||||
|
|
||||||
|
When mytt(command) is myem(not) a builtin, mytt(${ command }) does fork, and
|
||||||
|
typically forks the same number of times as mytt($(command)), because in
|
||||||
|
the latter case zsh usually optimizes the final fork into an exec.
|
||||||
|
|
||||||
|
Redirecting input from files has subtle differences:
|
||||||
|
|
||||||
|
mytt($(<file)) is optimized to read from mytt(file) without forking, but
|
||||||
|
per above it removes trailing newlines.
|
||||||
|
|
||||||
|
mytt(${<file}) is a substitution error.
|
||||||
|
|
||||||
|
mytt(${ <file }) copies mytt(file) using the mytt(NULLCMD) programs, then
|
||||||
|
reads and substitutes the contents of the copy. Also, this fails if the
|
||||||
|
mytt(CSH_NULLCMD) or mytt(SH_NULLCMD) options are in effect, so it does
|
||||||
|
not work in emulation modes.
|
||||||
|
|
||||||
|
mytt(${|<file}) copies mytt(file) to the standard output using mytt(NULLCMD)
|
||||||
|
but substitutes nothing because there is no assignment to mytt(REPLY). It
|
||||||
|
fails in emulation modes.
|
||||||
|
|
||||||
|
mytt(${|IFS= read -rd '' <file}) is therefore the best solution for files
|
||||||
|
that do not contain nul bytes, because it copies the file directly into
|
||||||
|
the local mytt(REPLY) and then substitutes that.
|
||||||
|
|
||||||
chapter(How to get various things to work)
|
chapter(How to get various things to work)
|
||||||
|
|
||||||
sect(Why does mytt($var) where mytt(var="foo bar") not do what I expect?)
|
sect(Why does mytt($var) where mytt(var="foo bar") not do what I expect?)
|
||||||
|
|
Loading…
Reference in a new issue