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

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



On Thu, Nov 13, 2008 at 02:52:59PM +0000, Peter Stephenson wrote:
> Stephane Chazelas wrote:
> > The patch below seems to fix it. It just removes the special
> > case of f() { }. I don't why it was there in the first place.
> > rev 1.1 of parse.c already had it.
> 
> That's because you've made all functions with braces parse as if they
> contain current shell structures; you'll see they're output with an
> unnecessary extra set of "{"s.  This works because it just makes the
> code behave like the non-confusing way to do it, with the redirection
> inside the function.
[...]

Well, it depends how you regard the function syntax.

In the Bourne shell and its derivatives, defining a function
is really sticking foo() in front of a command. The "{" and "}"
are not part of the syntax of a function definition.

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.

bash allows:

foo() for i do echo "$i"; done
but not
foo() echo "$*"

contrary to all the other Bourne like shells which allow both.

Now, I agree that

$ /tmp/Z/bin/zsh -c 'f() { :; }; typeset -f'
f () {
        {
                :
        }
}

is not ideal ;). Looks like the fix is not as easy as that.

-- 
Stéphane



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