Functions in Shell Scripts

Functions are easy to define in scripting :

function function_name
{



}

function --> keyword .
function_name---> valid identifier .

Example :

##variables
today=$(date +"%x %r ")

##functions

function todayIS
{

echo $today

}

Output will be : Monday 26 January 2009 10:04:59 PM IST {something like this}


It is simple easy and yet very powerful to use functions(methods) in your code :).
Be careful in selecting the function and variable names , note that it wont conflict with the reserved keywords of the shell like PATH,HOME etc
Share this