ADD TWO NUMBERS IN SHELL SCRIPT
In this shell script article we are going to learn to:
add two numbers in shell script
Lets see the steps to find the sum of two numbers in unix shell script.
STEPS TO ADD NUMBERS IN SHELL:
Follow the below steps to add two numbers in unix:
Use ‘clear’ command to clear the screen.
Use ‘echo’ command to print output.
‘-n’ is used to keep the cursor in the same line.
Take two inputs and store it in two different variables.
You can use ‘echo’ or ‘expr’ to calculate arithmetic operation. But here I have used just dollar sign to perform operation.
At last just, print the result
Given below is code to add two numbers in shell script
echo -n "Enter 1st number: "
echo -n "Enter 2nd number: "
sum=$(($first_number + $second_number))
echo "Sum of $first_number and $second_number: "$sum
WRITTEN IN CYGWIN:
use ':wq' command to save and quit the files.
use 'bash' command to execute code.
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Page Views :
Published Date :