Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Segfault in =( ) substitution



On 18 October 2012 16:07, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Oct 17,  9:16pm, Peter Stephenson wrote:
> :
> : I suppose it's worth pointing out you can now do things like this...
> :
> : () {
> :    print File $1:
> :    cat $1
> : } =(print This be the verse)
>
> More than worth pointing out, it's worth putting in the docs as an
> example!
>
> Question is, whether it's better as an example of anonymous functions or
> of process substitution.

Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.146
diff -p -u -r1.146 expn.yo
--- Doc/Zsh/expn.yo	18 Oct 2012 08:28:48 -0000	1.146
+++ Doc/Zsh/expn.yo	18 Oct 2012 15:24:50 -0000
@@ -483,6 +483,24 @@ example(LPAR()mycmd =(myoutput)RPAR() &!
 as the forked subshell will wait for the command to finish then remove
 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)
 sect(Parameter Expansion)
 cindex(parameter expansion)

pws



Messages sorted by: Reverse Date, Date, Thread, Author