1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-19 03:31:14 +02:00

30740: add example of process substitution using anonymous function

This commit is contained in:
Peter Stephenson 2012-10-18 16:18:57 +00:00
parent a02f3b6910
commit 02225925ef
2 changed files with 22 additions and 1 deletions

View file

@ -1,5 +1,8 @@
2012-10-18 Peter Stephenson <pws@csr.com> 2012-10-18 Peter Stephenson <pws@csr.com>
* 30740: Doc/Zsh/expn.yo: add example of process substitution
with anonymous function.
* c.f. users/17330: Doc/Zsh/expn.yo: fix reference to splitting * c.f. users/17330: Doc/Zsh/expn.yo: fix reference to splitting
rule in parameter expansion rules. rule in parameter expansion rules.
@ -274,5 +277,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.5746 $ * $Revision: 1.5747 $
***************************************************** *****************************************************

View file

@ -483,6 +483,24 @@ example(LPAR()mycmd =(myoutput)RPAR() &!)
as the forked subshell will wait for the command to finish then remove as the forked subshell will wait for the command to finish then remove
the temporary file. the temporary file.
A general workaround to ensure a process substitution endures for
an appropriate length of time is to pass it as a parameter to
an anonymous shell function (a piece of shell code that is run
immediately with function scope). For example, this code:
example(LPAR()RPAR() {
print File $1:
cat $1
} =+LPAR()print This be the verse+RPAR())
outputs something resembling the following
example(File /tmp/zsh6nU0kS:
This be the verse)
The temporary file created by the process substitution will be deleted
when the function exits.
texinode(Parameter Expansion)(Command Substitution)(Process Substitution)(Expansion) texinode(Parameter Expansion)(Command Substitution)(Process Substitution)(Expansion)
sect(Parameter Expansion) sect(Parameter Expansion)
cindex(parameter expansion) cindex(parameter expansion)