POSIX states that a function body is a compound command. This means that, among others, the following are legal (and widely supported):
% foo() { echo hello; }
% foo
hello
% bar() ( echo hello )
% bar
hello
% xyzzy() if true; then echo wizard; else echo muggle; fi
% xyzzy
wizard
% frobnitz() for i in $(seq 3); do echo $i; done
% frobnitz
1
2
3
Some shells also accept a simple command (in addition to compound) as the body. For instance, in dash and zsh:
% baz() echo hello
% baz
hello
However, flash's Parser::parse_function_definition() is too restrictive and only accepts a function body if wrapped in curly braces.
POSIX states that a function body is a compound command. This means that, among others, the following are legal (and widely supported):
Some shells also accept a simple command (in addition to compound) as the body. For instance, in
dashandzsh:However, flash's
Parser::parse_function_definition()is too restrictive and only accepts a function body if wrapped in curly braces.