Bash Functions: Difference between revisions
Jump to navigation
Jump to search
(→Syntax) |
No edit summary |
||
Line 5: | Line 5: | ||
=Defintion= | =Defintion= | ||
=Syntax= | ==Syntax== | ||
[function] ''function-name''() { | [function] ''function-name''() { | ||
Line 13: | Line 13: | ||
The "function" keyword is optional. | The "function" keyword is optional. | ||
=Arguments= | ==Arguments== | ||
The function does not declare its arguments in the signature. They are available in the function's body as $1, $2, etc. | The function does not declare its arguments in the signature. They are available in the function's body as $1, $2, etc. | ||
=Return Values= | ==Return Values== | ||
A bash function does not return a value, it only allows to set an ''exit status'', which is a numerical value. 0 indicates success and a non-zero value indicates failure. The exit status is declared with the "return" keyword: | |||
function f() { | |||
... | |||
return 0 | |||
} | |||
=Executing a Function in Background= | =Executing a Function in Background= |
Revision as of 23:45, 15 July 2017
Internal
Defintion
Syntax
[function] function-name() { ... }
The "function" keyword is optional.
Arguments
The function does not declare its arguments in the signature. They are available in the function's body as $1, $2, etc.
Return Values
A bash function does not return a value, it only allows to set an exit status, which is a numerical value. 0 indicates success and a non-zero value indicates failure. The exit status is declared with the "return" keyword:
function f() { ... return 0 }