For example:
Bash-Prog-Intro-HOWTO
function foo() {}
I make search queries in info bash and look in releted chapters of POSIX for function keyword but nothing found.
What is function keyword used in some bash scripts? Is that some deprecated syntax?
The
functionkeyword is optional when defining a function in Bash, as documented in the manual:The first form of the syntax is generally preferred because it’s compatible with Bourne/Korn/POSIX scripts and so more portable.
That said, sometimes you might want to use the
functionkeyword to prevent Bash aliases from colliding with your function’s name. Consider this example:Here,
'foo'is replaced by the text of the alias of the same name because it’s the first word of the command. Withfunctionthe alias is not expanded: