Reputation: 1702
in bash we can write function , but actually we have two ways ( two syntax ) ,
Please advice
What the differences between example1 to example2
Or maybe there are no any differences?
function I_love_function
{
.
.
}
I_love_function ()
{
.
.
}
How to call the function I_love_function
Upvotes: 2
Views: 787
Reputation: 75568
I_love_function () { }
is compatible with POSIX/original sh-based shells but if your script is only meant to run in Bash, then there won't be much difference and more of just a preference.
Personally I prefer function func_name { }
format since ()
seems meaningless to me as it doesn't explicitly specify the accepted arguments to the function.
Upvotes: 1
Reputation: 2086
From: http://www.gnu.org/software/bash/manual/bashref.html#Shell-Functions
Functions are declared using this syntax:
name () compound-command [ redirections ]
or
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.
Upvotes: 2