bash - difference between "function foo() {}" and "foo() {}"
lundi 9 novembre 2015 à 16:10Httqm's Links
TL;DR : (almost) no difference when working on GNU/Linux. "foo() {}" is the POSIX syntax, is more portable, and has less chances of failing when moving scripts to other shells/proprietary Unices.
From the man pages :
Ksh :
function varname { list ;}
varname () { list ;}
Bash :
[ function ] name () compound-command [redirection]
Summary :
foo() commands
POSIX syntax
Supported by Bourne like shells
function foo { ...; }
Korn shell syntax
NOT POSIX
Supported by Bash and Zsh for compatibility with Ksh
function foo() { ...; }
do not use this
(Permalink) (Profil)
TL;DR : (almost) no difference when working on GNU/Linux. "foo() {}" is the POSIX syntax, is more portable, and has less chances of failing when moving scripts to other shells/proprietary Unices.
From the man pages :
Ksh :
function varname { list ;}
varname () { list ;}
Bash :
[ function ] name () compound-command [redirection]
Summary :
foo() commands
POSIX syntax
Supported by Bourne like shells
function foo { ...; }
Korn shell syntax
NOT POSIX
Supported by Bash and Zsh for compatibility with Ksh
function foo() { ...; }
do not use this
(Permalink) (Profil)