PROJET AUTOBLOG


Shaarli - Les discussions de Shaarli

Archivé

Site original : Shaarli - Les discussions de Shaarli du 23/07/2013

⇐ retour index

bash - difference between "function foo() {}" and "foo() {}"

lundi 9 novembre 2015 à 16:10
Httqm'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)