Bash Programming : Addition

Here I tried this on ubuntu

To create the file

cat>add

code type in the terminal:

read a
read b
sum=`expr $a + $b`
echo $sum

don’t give space after or before equal sign

save the file and close editing mode:

ctrl+d

change the permission of this file:

chmod +x add

to show the output

sh add
4
5
9

Shortcut method for addition or any other:
create a file with cat then type code from the below in one line

echo `expr $1 + $2 + $3`

here 1 2 and 3 is variable is taking input from user and also giving teh output so we sue $ before them….it is the shortcut method

then just type

sh shortcut 3 4 5

and you will get the addition of this variables

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.