zsh-workers
 help / color / mirror / code / Atom feed
* {var}>& redirections with complex commands
@ 2011-08-09  3:46 Bart Schaefer
  2011-08-09 18:16 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2011-08-09  3:46 UTC (permalink / raw)
  To: zsh-workers

There are a lot of cases in which ordinary numeric redirections would be
accepted but where one cannot use these redirections.  E.g. this is OK:

torch% foo() { print $one $two }
torch% foo {one}<&0 {two}<&0  
11 12

But none of these are:

torch% {one}<&0 {two}<&0 foo                               
zsh: parse error near `{'
torch% ( print $one $two ) {one}<&0 {two}<&0
zsh: parse error near `{'
torch% { print $one $two } {one}<&0 {two}<&0
zsh: parse error near `{'

Same for various loop constructs, anonymous functions, etc.

{var} can only be used at the end of a simple command, and therefore the
only ways to reference the fd via the variable are to create the fd with
"exec" or to use a function. This should at least be clarified in the
documentation.


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

* Re: {var}>& redirections with complex commands
  2011-08-09  3:46 {var}>& redirections with complex commands Bart Schaefer
@ 2011-08-09 18:16 ` Peter Stephenson
  2011-08-10 23:05   ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2011-08-09 18:16 UTC (permalink / raw)
  To: zsh-workers

On Mon, 08 Aug 2011 20:46:14 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> There are a lot of cases in which ordinary numeric redirections would be
> accepted but where one cannot use these redirections.

In those cases the "{" is interpreted differently and it would take a
lot of lookahead to fix.  In fact, it's not really fixable without
breaking standard zsh syntax ...

{echo}>&2

means

{ echo } 1>&2

whenever it occurs in command position, whatever follows.

I don't think that's a problem.  They aren't actually redirections at
all, just ways of opening (and closing) file descriptors, so tacking
them onto the start or end of complex commands doesn't actually do
anything particularly useful.  There's no implicit closing when
they are associated with a block (though obvious there is if they are in
a subshell).

I've given them a separate section in the manual.

Index: Doc/Zsh/redirect.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/redirect.yo,v
retrieving revision 1.10
diff -p -u -r1.10 redirect.yo
--- Doc/Zsh/redirect.yo	26 Sep 2005 18:34:51 -0000	1.10
+++ Doc/Zsh/redirect.yo	9 Aug 2011 18:10:20 -0000
@@ -149,13 +149,33 @@ file descriptor 2 would be associated
 with the terminal (assuming file descriptor 1 had been)
 and then file descriptor 1 would be associated with file var(fname).
 
-If instead of a digit one of the operators above is preceded by
-a valid identifier enclosed in braces, the shell will open a new
-file descriptor that is guaranteed to be at least 10 and set the
-parameter named by the identifier to the file descriptor opened.
-No whitespace is allowed between the closing brace and the redirection
-character.  The option tt(IGNORE_BRACES) must not be set.
-For example:
+The `tt(|&)' command separator described in
+ifzman(em(Simple Commands & Pipelines) in zmanref(zshmisc))\
+ifnzman(noderef(Simple Commands & Pipelines))
+is a shorthand for `tt(2>&1 |)'.
+
+The various forms of process substitution, `tt(<LPAR())var(list)tt(RPAR())',
+and `tt(=LPAR())var(list)(RPAR())' for input and
+`tt(>LPAR())var(list)tt(RPAR())' for output, are often used together with
+redirection.  For example, if var(word) in an output redirection is of the
+form `tt(>LPAR())var(list)tt(RPAR())' then the output is piped to the
+command represented by var(list).  See
+ifzman(\
+em(Process Substitution) in zmanref(zshexpn))\
+ifnzman(\
+noderef(Process Substitution)).
+sect(Opening file descriptors using parameters)
+cindex(file descriptors, use with parameters)
+cindex(parameters, for using file descriptors)
+
+When the shell is parsing arguments to a command, and the shell option
+The option tt(IGNORE_BRACES) is not set, a different form of
+redirection is allowed: instead of a digit before the operator
+there is a valid shell identifier enclosed in braces.  The shell will
+open a new file descriptor that is guaranteed to be at least 10 and set
+the parameter named by the identifier to the file descriptor opened.  No
+whitespace is allowed between the closing brace and the redirection
+character.    For example:
 
 indent(... {myfd}>&1)
 
@@ -181,8 +201,12 @@ using it for allocating a file descripto
 
 Note that this mechanism merely allocates or closes a file descriptor; it
 does not perform any redirections from or to it.  It is usually convenient
-to allocate a file descriptor prior to use as an argument to tt(exec).  The
-following shows a typical sequence of allocation, use, and closing of a
+to allocate a file descriptor prior to use as an argument to tt(exec).
+The syntax does not in any case work when used around complex commands
+such as parenthesised subshells or loops, where the opening brace is
+interpreted as part of a command list to be executed in the current shell.
+
+The following shows a typical sequence of allocation, use, and closing of a
 file descriptor:
 
 example(integer myfd
@@ -194,22 +218,6 @@ Note that the expansion of the variable 
 occurs at the point the redirection is opened.  This is after the expansion
 of command arguments and after any redirections to the left on the command
 line have been processed.
-
-The `tt(|&)' command separator described in
-ifzman(em(Simple Commands & Pipelines) in zmanref(zshmisc))\
-ifnzman(noderef(Simple Commands & Pipelines))
-is a shorthand for `tt(2>&1 |)'.
-
-The various forms of process substitution, `tt(<LPAR())var(list)tt(RPAR())',
-and `tt(=LPAR())var(list)(RPAR())' for input and
-`tt(>LPAR())var(list)tt(RPAR())' for output, are often used together with
-redirection.  For example, if var(word) in an output redirection is of the
-form `tt(>LPAR())var(list)tt(RPAR())' then the output is piped to the
-command represented by var(list).  See
-ifzman(\
-em(Process Substitution) in zmanref(zshexpn))\
-ifnzman(\
-noderef(Process Substitution)).
 sect(Multios)
 cindex(multios)
 pindex(MULTIOS, use of)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: {var}>& redirections with complex commands
  2011-08-09 18:16 ` Peter Stephenson
@ 2011-08-10 23:05   ` Mikael Magnusson
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2011-08-10 23:05 UTC (permalink / raw)
  To: zsh-workers

On 9 August 2011 20:16, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Mon, 08 Aug 2011 20:46:14 -0700
> +When the shell is parsing arguments to a command, and the shell option
> +The option tt(IGNORE_BRACES) is not set, a different form of

> +character.    For example:

I took the liberty of removing the doubled words and extraneous whitespace here.

-- 
Mikael Magnusson


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

end of thread, other threads:[~2011-08-10 23:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-09  3:46 {var}>& redirections with complex commands Bart Schaefer
2011-08-09 18:16 ` Peter Stephenson
2011-08-10 23:05   ` Mikael Magnusson

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).