Sunday 17 January 2016

Bash shell script functions

#!/bin/bash
#definition of function
#passing arg to function
#command line args
#exit status of function

#define your function here
Hello() {
        echo "Hello World"
}

#Invoke the function
Hello

#Passing the values
Hello() {
        echo "Hello World $1 $2"
}

#Invoke the function
Hello Sankar S

#return  values
Hello () {
        echo "Hello $1 $2"
        echo $@
        return 0
}

Hello Sankar Suriya
echo "Exit status of Hello Function : $?"

#command line arguments
numofarg=$#

echo "Total Number Of Arguments Are : $numofarg"

if [ $numofarg -gt 0 ]
then
        for i in $@
        do
                echo "print $i"
        done
fi

No comments:

Post a Comment