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

Re: [PATCH] Re: f() { ...; } > file



On Thu, Nov 13, 2008 at 03:03:35PM +0000, Stephane Chazelas wrote:
[...]
> Note that POSIX has specified it with a restriction in that you
> can only stick "foo()" in front of complex command, and bash is
> the only shell to enforce that restriction.
[...]

Sorry the proper term is "compound command". Here is the text
from SUSv3:

SUS>   The format of a function definition command is as
SUS>   follows:
SUS> 
SUS> fname() compound-command[io-redirect ...]
SUS> 
[...]
SUS>   The argument compound-command represents a compound
SUS>   command, as described in Compound Commands.
SUS> 
SUS>   When the function is declared, none of the expansions in
SUS>   Word Expansions shall be performed on the text in
SUS>   compound-command or io-redirect; all expansions shall be
SUS>   performed as normal each time the function is called.
SUS>   Similarly, the optional io-redirect redirections and any
SUS>   variable assignments within compound-command shall be
SUS>   performed during the execution of the function itself,
SUS>   not the function definition. See Consequences of Shell
SUS>   Errors for the consequences of failures of these
SUS>   operations on interactive and non-interactive shells.
[...]
SUS>   The compound-command shall be executed whenever the
SUS>   function name is specified as the name of a simple
SUS>   command (see Command Search and Execution). The operands
SUS>   to the command temporarily shall become the positional
SUS>   parameters during the execution of the compound-command;
SUS>   the special parameter '#' also shall be changed to
SUS>   reflect the number of operands. The special parameter 0
SUS>   shall be unchanged. When the function completes, the
SUS>   values of the positional parameters and the special
SUS>   parameter '#' shall be restored to the values they had
SUS>   before the function was executed. If the special built-in
SUS>   return is executed in the compound-command, the function
SUS>   completes and execution shall resume with the next
SUS>   command after the function call.

So, at the moment, zsh is not conformant. The patch I suggested
seems to fix it but introduces some display glitches.

-- 
Stéphane



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