calling function in echo command

sam_2012
sam_2012 used Ask the Experts™
on
Hi Team,

Below is the shell script i have written , I have written a function to add two numbers and calling that function as part of echo statement. But iam not getting the results.

#!/bin/bash


if [ $# -ne 2 ]
then
        echo " Wrong number of arguments. Usage: scriptname number1 number2"
        exit 1
fi


add()
{
        sum=$[  $1 + $2 ]
}

echo " The Sum of $1 + $2 is : S(   add )"

calling the script addnum 10 20

Any help is really appreciated.


~                                                                              
~                                                                              
~                                                                              
~
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
#!/bin/bash


if [ $# -ne 2 ]
then
        echo " Wrong number of arguments. Usage: scriptname number1 number2"
        exit 1
fi

add()
{
       sum=$(( $1 + $2 ))
       echo $sum
}

echo " The Sum of $1 + $2 is : S( `add $1 $2` )"

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial