Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: {var}>& redirections with complex commands
On Mon, 08 Aug 2011 20:46:14 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author