20 January 2012

Shell Script to add two numbers by the use of Function

1 comment

Q. How do I write Bash Script to add two numbers using function


Ans:

#!/bin/bash
#function to add two numbers
add()
{
x=$1
y=$2
echo -e "Number entered by u are: $x and $y"
echo "sum of $1 and $2 is `expr $x + $y` "
}
# main script
echo "enter first number"
read first
echo "enter second number"
read sec
#calling function
add $first $sec
echo "end of the script"

Output


shell script to add two numbers using function

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

1 comment:

  1. Thnx its gud who want to learn shell schripting as well as programming basics

    ReplyDelete