bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function definition syntax inconsistencies


From: Stephane Chazelas
Subject: Re: Function definition syntax inconsistencies
Date: Thu, 5 Jun 2008 08:32:07 +0100
User-agent: Mutt/1.5.16 (2007-09-19)

On Thu, Jun 05, 2008 at 06:31:36AM +0200, Jan Schampera wrote:
[...]
>         The function definition is allowed in 3 forms:
>         1. NAME() ...

That's the Bourne and POSIX syntax

>         3. function NAME ...

That's the ksh syntax. It's probably only there for
compatibility with ksh (note that bash doesn't make the same
distinctions as AT&T ksh does when using that syntax). ksh
doesn't support function foo (echo), so it's fine with bash not
to either, I'd say.

>         2. function NAME() ...
[...]

Not sure where that syntax comes from. It could be that it works
by accident or it could be that someone thought that it was a
good idea to have yet another syntax. It happens to be the same
syntax as awk.

In anycase, given that those syntaxes are not different
functionnaly (contrary to in ksh), I think it would be a good
idea to have the manual say that only "1." should be used as
it's the standard one.

I suspect this:
$ sh -c 'function() { echo a; }; function'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `function() { echo a; }; function'

breaks POSIX conformance, BTW (but then it's the same for AT&T
ksh, pdksh, zsh).

-- 
Stéphane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]