bug-bash
[Top][All Lists]
Advanced

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

Shell Grammar man page function definition


From: Mike Jonkmans
Subject: Shell Grammar man page function definition
Date: Sun, 28 Feb 2021 18:38:42 +0100

Hi,

The manual page says:
        If the function reserved word is used, but the parentheses are not 
supplied,
        the braces are required.

But it seems that from all the compound commands,
only a subshell is not possible.

Some examples that work:
        function x { :; } ## as expected
        function x if :; then :; fi
        function x (( 42 ))
        function x [[ 42 ]]
        function x for x do :; done
        function x for (( ; 42 - 42 ; )); do :; done

What does not work:
        function x ( : )


>From looking at the bash grammar I am not sure why a subshell does not work.
As the subshell can be differentiated from the optional parentheses.


Though it may be handy to disallow a subshell.
If in the future named parameters would become a possibility.
E.g.
        function x (a=$1 b=$2)
        { echo "$a$b; }
would become ambiguous.


Note that the Posix grammar doesn't mention the word 'function'.
Posix does mention it, as reserved word recognized by 'some implementations'
and causing undefined behavior.


Regards, Mike Jonkmans



reply via email to

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