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

Re: PATCH: allocating a new file descriptor

On Apr 14, 10:49am, Peter Stephenson wrote:
} Subject: Re: PATCH: allocating a new file descriptor
} I can add documentation to point this out if you think it would be
} useful.

Possibly so.

} It would also be possible to make NO_CLOBBER check that in {myfd}>stuff,
} $myfd doesn't already point to an fd with an FDT_EXTERNAL flag.  That
} would prevent overwriting.  I quite like that idea.

I do, too.

} For more complicated cases you might need to set myfd to 0 first

Or (more appropriately, I would think) unset it, no?

(Given discipline functions, one could even arrange that myfd closes
its descriptor upon unset.)

} Fortuitously,
}   print This is a log file {myfd}>~/tmp/logfile.txt >&$myfd
} works; $myfd is substituted at the right point.  That's quite lucky,
} since most expansions have been done by this point.

At first I thought that was a little odd, but I guess really it's OK,
because this ...

    print ${myfd::=2} $myfd

... also prints "2 2".

It might be useful to add a note somewhere (the "Expansion" section?)
about the ordering of parameter expansion relative to redirections.

} However, there's also the point that if you use this after an external
} command the shell has already forked and the fd doesn't appear in the
} parent shell. 

That's a very interesting point.  This works:

    /bin/echo foo {myfd}>>(tr a-z A-Z) >&$myfd

But this causes the shell to hang forever:

    print foo {myfd}>>(tr a-z A-Z) >&$myfd

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

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