Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in defining function in bash

Tags:

function

bash

I have seen function defined two ways in bashrc:

dosomething() { ... } 

and

function dosomething() { ... } 

What difference does it make to use the function declaration?

like image 423
Strapakowsky Avatar asked Nov 27 '25 10:11

Strapakowsky


1 Answers

http://www.gnu.org/s/bash/manual/bash.html#Shell-Functions

Functions are declared using this syntax:

 [ function ] name () compound-command [ redirections ]

This defines a shell function named name. The reserved word function is optional. If the function reserved word is supplied, the parentheses are optional.

function and omitting parentheses is bash-specific. So to be more portable, don't use it.

like image 150
plundra Avatar answered Nov 29 '25 09:11

plundra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!