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

Re: {fd}< and compound commands



2011-09-15 09:22:35 -0400, Chet Ramey:
> On 9/15/11 9:09 AM, Peter Stephenson wrote:
> 
> >> does that feature come from another shell/language?
> > 
> > Yes, we discussed it.  I think one of us (not me) suggested the syntax.
> 
> Oliver Kiddle.
[...]

Oh, I hadn't realised bash supported it too (since
bash-4.1-alpha according to CHANGES).

For completeness, looks like bash behaves like ksh93 (no close,
works with compound commands).

So looks like if we want to be portable accross all 3 shells,
we'd need to write it:

exec {fd}> file
... >&$fd
exec {fd}>&-

BTW, zsh protects its own internal fds. Looks like bash and
ksh93 don't:

~$ zsh -c 'fd=11; exec {fd}>&-'
zsh:1: file descriptor 11 used by shell, not closed
~$ bash -c 'fd=10; { exec {fd}>&-; } 2> /dev/null; echo test >&2'
~$ ksh93 -c 'fd=10; { exec {fd}>&-; } 2> /dev/null; echo test >&2'
~$

-- 
Stephane



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