Add Two Numbers Using Shell Script: Bash or Shell Script is the command line language & Unix Shell. The Linux, Unix & Mac OS adopt this technology and made their default shell as Bash Shell Scripting. In this tutorial, you will learn about adding two number in shell script with basic formulae and working example.
Formulae To Add Two numbers in Shell:
The below script will takes the input from the user and add the input values and print the values in the new variable. This script has three variables totally, Two variables are used to receive the input from the user and the third variable is used to print the added value of the two variable.
Shell Script 1:
The above script is used to add the two predefined values and print the added value in the third variable.
Shell Script 2:
In the above script, The $a & $b represents the first & second argument passed as the command line arguments. The output value will print in the third variable $add.
The sample output of the above script is,
Example of Adding Two numbers in Shell:
This is the example script to receive the values for the variables from the user in runtime compilation. Which receives the two variables from the user and print the added value in the third variable.
The output of the above script is,
From the above output, The Script received the values for the two variables from the user and add the two values and print the added value in the third value. In this way, you can use the shell script to add the two variables or number in the shell script.
That’s it. You can use the above scripts to add the two values or numbers in a shell script in Linux. If you have any queries related to this topic and then feel free to comment us below.
For more articles, Kindly Visit our HomePageHomePage