Skip to content

Instantly share code, notes, and snippets.

Last active May 22, 2018
What would you like to do?
shell script to add two numbers using function
# above line used to specify which shell to be used to execute the program
add() # function to add 2 numbers
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
# run the program by ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment