Skip to content

Instantly share code, notes, and snippets.

@dharshan
Last active May 22, 2018 01:39
Show Gist options
  • Save dharshan/8074cf841d3e6540f48d1eef23b4d08a to your computer and use it in GitHub Desktop.
Save dharshan/8074cf841d3e6540f48d1eef23b4d08a to your computer and use it in GitHub Desktop.
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