Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Wednesday, 14 November 2012

Functions in Linux

Function need to be declared FIRST before it is used.

functionName(){
    if [ "$1" == "1" ]; then
         echo "paramether is 1"
   else
       echo "parameter is not 1"
    fi
    if [ "$2" != "" ]; then
       echo "there is second parameter"
    fi
}

and call it like this:

functionName

OR pass an argument:

functionName 1

OR more arguments:

functionName 1 aString