On Tue, Aug 26, 2008 at 5:38 PM, R. Bernstein <[EMAIL PROTECTED]> wrote:
> Pierre Gaston writes:
> > On Tue, Aug 26, 2008 at 4:49 PM, R. Bernstein <[EMAIL PROTECTED]> wrote:
> > > Pierre Gaston writes:
> > > > On Tue, Aug 26, 2008 at 5:41 AM, R. Bernstein <[EMAIL PROTECTED]>
> wrote:
> > > > > Both zsh and ksh have a way to open a file or duplicate a file
> > > > > descriptor and let the interpreter pick the descriptor saving the
> > > > > newly-allocated file descriptor number in a variable. In particular:
> > > > >
> > > > > exec {fd}<&0
> > > > >
> > > > > will duplicate stdin and save the newly allocated file-descriptor
> > > > > number to fd. Also:
> > > > >
> > > > > exec {fd}<filename
> > > > >
> > > > > opens filename with a new file descriptor and saves the number
> > > > > allocated in fd. Short of going outside of the language and using
> > > > > lsof, /proc, or the processes table, I haven't been able to figure
> out
> > > > > how to do the corresponding thing in bash. Is there a way?
> > > > >
> > > > > If not, it would be great if a future version had this extension
> that
> > > > > zsh and ksh both seem to have.
> > > > >
> > > > > Thanks!
> > > >
> > > > This is a standard behaviour and you can do this in pretty much any
> > > > shell out there, including bash.
> > >
> > > Really? It doesn't seem to be documented in bashref. And when I tried
> just
> > > a moment ago:
> > >
> > > $ {fd}<&0
> > > {fd}<&0
> > > bash: {fd}: command not found
> > > $ bash --version
> > > bash --version
> > > GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
> > >
> > > Perhaps you are thinking of the variation without braces?
> > >
> >
> > well, I was thinking of the normal redirection syntax:
> > exec 3<&0
> >
> > I doubt '{fd}<&0' is meaningfull anywhere.....in ksh {fd} tries to
> > run the command {fd} like in bash
> > in zsh it tries to run the command "fd"
> > What are you talking about???
> >
>
> I suppose this is new enough stuff that you would need recent ksh
> or zsh version to see it. From a recent ksh 93t manual:
>
> If one of the above, other than >&- and the ># and ># forms, is
> preceded by ing space, then a file descriptor number > 10 will
> be selected by the shell and stored in the variable varname.
> If >&- or the any of the ># and ># forms is preceded by
> {varname} the value of varname defines the file descriptor to
> close or position. For example:
>
> ... 2>&1
>
> means file descriptor 2 is to be opened for writing as a duplicate of
> file descriptor 1 and
>
> exec {n}<file
>
> means open file named file for reading and store the file descriptor
> number in variable n.
>
> zsh has something similar.
>
ah sorry then. I don't have ksh and zsh version recent enough