28 Şubat 2021 Pazar tarihinde Mike Jonkmans <bash...@jonkmans.nl> yazdı:
> 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 ( : ) Works fine here. bash-5.1$ function x ( : ) bash-5.1$ declare -f x 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 > > -- Oğuz