zsh-users
 help / color / mirror / code / Atom feed
* multi-digit file descriptors
@ 2015-02-11 16:26 Vincent Lefevre
  2015-02-11 17:27 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Vincent Lefevre @ 2015-02-11 16:26 UTC (permalink / raw)
  To: zsh-users

Contrary to bash and mksh, zsh doesn't support file descriptors with
multiple digits. Considered the following file "redir".

----------------------------------------
( echo foo >&9; ) 9>my_file
cat my_file

( echo bar >&10; ) 10>my_file
cat my_file
----------------------------------------

xvii% bash redir
foo
bar
xvii% mksh redir
foo
bar
xvii% zsh redir
foo
redir:4: parse error near `10'

The behavior of dash and ksh93 is similar to zsh. But is there any
reason?

BTW, POSIX doesn't seem to restrict file descriptors to 1 digit.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-11 16:26 Vincent Lefevre
@ 2015-02-11 17:27 ` Bart Schaefer
  2015-02-11 17:46   ` Peter Stephenson
  2015-02-12 10:16   ` Vincent Lefevre
  0 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2015-02-11 17:27 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

On Feb 11, 2015 8:28 AM, "Vincent Lefevre" <vincent@vinc17.net> wrote:
>
> The behavior of dash and ksh93 is similar to zsh. But is there any
> reason?

Zsh reserves descriptors 10 and up for internal use; for example, 10 is
nearly always a copy of the original input terminal in an interactive shell.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-11 17:27 ` Bart Schaefer
@ 2015-02-11 17:46   ` Peter Stephenson
  2015-02-12 10:24     ` Vincent Lefevre
  2015-02-12 10:16   ` Vincent Lefevre
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2015-02-11 17:46 UTC (permalink / raw)
  To: Zsh Users

On Wed, 11 Feb 2015 09:27:51 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Feb 11, 2015 8:28 AM, "Vincent Lefevre" <vincent@vinc17.net> wrote:
> >
> > The behavior of dash and ksh93 is similar to zsh. But is there any
> > reason?
> 
> Zsh reserves descriptors 10 and up for internal use; for example, 10 is
> nearly always a copy of the original input terminal in an interactive shell.

You can grab use of one yourself with the recommended syntax (we
actually agreed this with David Korn):

  local foo
  exec {foo}>blah
  echo bleugh >&$foo

and given what Bart mentioned we wouldn't be that keen to open it up
more widely.

Note there's nothing magic about foo, it just contains a number.  So you
can do

  local foo=12
  exec {foo}>&-

etc.

pws


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
       [not found] <20150211162637.GA9083__22180.4416658872$1423672129$gmane$org@xvii.vinc17.org>
@ 2015-02-11 20:47 ` Stephane Chazelas
  0 siblings, 0 replies; 8+ messages in thread
From: Stephane Chazelas @ 2015-02-11 20:47 UTC (permalink / raw)
  To: zsh-users

2015-02-11 17:26:37 +0100, Vincent Lefevre:
> Contrary to bash and mksh, zsh doesn't support file descriptors with
> multiple digits. Considered the following file "redir".
> 
> ----------------------------------------
> ( echo foo >&9; ) 9>my_file
> cat my_file
> 
> ( echo bar >&10; ) 10>my_file
> cat my_file
> ----------------------------------------
> 
> xvii% bash redir
> foo
> bar
> xvii% mksh redir
> foo
> bar
> xvii% zsh redir
> foo
> redir:4: parse error near `10'
> 
> The behavior of dash and ksh93 is similar to zsh. But is there any
> reason?
> 
> BTW, POSIX doesn't seem to restrict file descriptors to 1 digit.
[...]

Related discussion on the austin-group mailing list:

http://thread.gmane.org/gmane.comp.standards.posix.austin.general/10094

-- 
Stephane


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-11 17:27 ` Bart Schaefer
  2015-02-11 17:46   ` Peter Stephenson
@ 2015-02-12 10:16   ` Vincent Lefevre
  2015-02-13  4:21     ` Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: Vincent Lefevre @ 2015-02-12 10:16 UTC (permalink / raw)
  To: Zsh Users

On 2015-02-11 09:27:51 -0800, Bart Schaefer wrote:
> On Feb 11, 2015 8:28 AM, "Vincent Lefevre" <vincent@vinc17.net> wrote:
> > The behavior of dash and ksh93 is similar to zsh. But is there any
> > reason?
> 
> Zsh reserves descriptors 10 and up for internal use; for example, 10 is
> nearly always a copy of the original input terminal in an interactive shell.

But this doesn't explain the error message, in particular...

On 2015-02-11 20:47:09 +0000, Stephane Chazelas wrote:
> Related discussion on the austin-group mailing list:
> 
> http://thread.gmane.org/gmane.comp.standards.posix.austin.general/10094

which mentions the use of 09. With zsh:

( echo foo >&09; ) 09>my_file

still gives an error:

redir:4: parse error near `09'

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-11 17:46   ` Peter Stephenson
@ 2015-02-12 10:24     ` Vincent Lefevre
  2015-02-12 16:45       ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Vincent Lefevre @ 2015-02-12 10:24 UTC (permalink / raw)
  To: zsh-users

On 2015-02-11 17:46:05 +0000, Peter Stephenson wrote:
> You can grab use of one yourself with the recommended syntax (we
> actually agreed this with David Korn):
> 
>   local foo
>   exec {foo}>blah
>   echo bleugh >&$foo

However this is not portable (not supported by dash and mksh).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-12 10:24     ` Vincent Lefevre
@ 2015-02-12 16:45       ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2015-02-12 16:45 UTC (permalink / raw)
  To: zsh-users

On Feb 12, 11:24am, Vincent Lefevre wrote:
} Subject: Re: multi-digit file descriptors
}
} On 2015-02-11 17:46:05 +0000, Peter Stephenson wrote:
} > You can grab use of one yourself with the recommended syntax (we
} > actually agreed this with David Korn):
} > 
} >   local foo
} >   exec {foo}>blah
} >   echo bleugh >&$foo
} 
} However this is not portable (not supported by dash and mksh).

Well, neither are multi-digit fd redirections (which was actually
sort of the point of that austin-group thread although it came at
the issue from a different direction).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: multi-digit file descriptors
  2015-02-12 10:16   ` Vincent Lefevre
@ 2015-02-13  4:21     ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2015-02-13  4:21 UTC (permalink / raw)
  To: Zsh Users

On Feb 12, 11:16am, Vincent Lefevre wrote:
} Subject: Re: multi-digit file descriptors
}
} On 2015-02-11 09:27:51 -0800, Bart Schaefer wrote:
} > Zsh reserves descriptors 10 and up for internal use; for example, 10 is
} > nearly always a copy of the original input terminal in an interactive shell.
} 
} But this doesn't explain the error message, in particular...
} 
} ( echo foo >&09; ) 09>my_file
} 
} still gives an error:
} 
} redir:4: parse error near `09'

"09>my_file" is parsed as "09" ">" "my_file", because zsh doesn't support
multi-digit descriptors on the left side of a redirect.  So what you have
is the same as

  { ( echo foo >&09 ) 09 } > my_file

Which is a parse error because you can't follow a subshell with an argument
list.

Zsh does support multi-digit descriptors on the right side, so >&09 is all
one token (and is the same as >&9 in this case).


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-02-13  4:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20150211162637.GA9083__22180.4416658872$1423672129$gmane$org@xvii.vinc17.org>
2015-02-11 20:47 ` multi-digit file descriptors Stephane Chazelas
2015-02-11 16:26 Vincent Lefevre
2015-02-11 17:27 ` Bart Schaefer
2015-02-11 17:46   ` Peter Stephenson
2015-02-12 10:24     ` Vincent Lefevre
2015-02-12 16:45       ` Bart Schaefer
2015-02-12 10:16   ` Vincent Lefevre
2015-02-13  4:21     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).