Skip to content

Instantly share code, notes, and snippets.

@dharshan
Last active May 22, 2018
Embed
What would you like to do?
shell script to add two numbers using function
#!/bin/bash
# above line used to specify which shell to be used to execute the program
add() # function to add 2 numbers
{
num1=$1
num2=$2
sum=`expr $num1 + $num2` # things insed the backtick `are evaluate or executed
echo "$num1 + $num2 = $sum"
}
echo "Enter first Number" # echo used to print the message to screen
read first_number # read and store the input from terminal
echo "enter second Number"
read second_number
add $first_number $second_number # call the add function
# give execution permission to file before running the program like bellow
# chmod +x add2.sh
# run the program by ./add2.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment