Friday, 4 September 2015

Shell Scripting - Addition given values

 

#!/bin/bash

echo "addition of X+Y"                 #it will print addition of X+Y line

echo "Enter X Value"                    #it will print Enter X value (you have to enter some value here

read X                                       #whatever the Value you enter above it will store as temp string

echo "Enter Y Value"                    #it will print Enter Y value (you have to enter some value here

read Y                                       #whatever the Value you enter for Y it will store as temp string

echo "X+Y = $X+$Y = $[ X+Y ]"    #Now we are auditioning X value and Y value you have provided

 

Explanation: echo will print whatever you write within the quotation marks. read means whatever the value you enter it will store that value, when you call that string it will print the stored value, in above script asking to enter some value as X and Y then we are addition both the values using '+'.

No comments:

Post a Comment