Linux Bash Scripting Tutorial


Functions

Functions
----------------
A function is a subroutine, code block that implements a set of operations, a "black box" that performs a specified task. or you can call it as a group of commands. shell functions let you to modularize your program by dividing it up into seperate tasks. functions are used wherever there is repetetive code. functions should be declared at the begining of the script. A functions is essentially a code block, which means stdin can be redirected function may have local variables, and may be recursive. Bash uses dynamic scoping model, whereby variables declared with local are visible inside that function and in other functions it calls. A function may use RETURN commands to return an exit status to the caller/calling shell program. it is also possible to have nested functions, i.e functions within functions A Bash function is a block of reusable code designed to perform a particular operation. Once defined, the function can be called multiple times within a script.

syntax:
     function funtionname{

		command...
	} [redirections]


  or 

function_name(){

	command ....
} [redirections]

adv bash bash ref manual linux shell scripting -

ADS