You are currently viewing Easy Shell Script to perform arithmetic operations

Easy Shell Script to perform arithmetic operations

Shell Script to perform ‘+’ arithmetic operation

Shell Script is written for performing several set of instructions. In this code we have tried to represent arithmetic operation. In this code ‘+’ (addition) operator is used. As you can see in this code, equation is written using ‘expr’ this command, this command is used for representing any equation in Shell Script.

				
					#!/bin/bash

echo "Enter first numbers : "
read a

echo "Enter second numbers : "
read b

c=`expr $a + $b`

echo 'The result is '$c

				
			

Shell Script to perform ‘-’ arithmetic operation

Shell Script is written for performing several set of instructions. In this code we have tried to represent arithmetic operation. In this code ‘-‘ (Subtraction) operator is used. As you can see in this code, equation is written using ‘expr’ this command, this command is used for representing any equation in Shell Script.

				
					#!/bin/bash

echo "Enter first numbers : "
read a

echo "Enter second numbers : "
read b

c=`expr $a - $b`

echo 'The result is '$c

				
			

Shell Script to perform ‘*’ arithmetic operation

Shell Script is written for performing several set of instructions. In this code we have tried to represent arithmetic operation. In this code ‘*’ (Multiplication) operator is used. As you can see in this code, equation is written using ‘expr’ this command, this command is used for representing any equation in Shell Script.

				
					#!/bin/bash

echo "Enter first numbers : "
read a

echo "Enter second numbers : "
read b

c=`expr $a \* $b`

echo 'The result is '$c


				
			

Shell Script to perform ‘/’ arithmetic operation

Shell Script is written for performing several set of instructions. In this code we have tried to represent arithmetic operation. In this code ‘/’ (Division) operator is used. As you can see in this code, equation is written using ‘expr’ this command, this command is used for representing any equation in Shell Script.

				
					#!/bin/bash

echo "Enter first numbers : "
read a

echo "Enter second numbers : "
read b

c=`expr $a / $b`

echo 'The result is '$c



				
			

Shell Script to perform ‘%’ arithmetic operation

Shell Script is written for performing several set of instructions. In this code we have tried to represent arithmetic operation. In this code ‘%’ (Modulus0) operator is used. This operator is basically used for finding out remainder. As you can see in this code, equation is written using ‘expr’ this command, this command is used for representing any equation in Shell Script.

				
					
#!/bin/bash

echo "Enter first numbers : "
read a

echo "Enter second numbers : "
read b
c=`expr $a % $b`

echo 'The result is '$c




				
			

Leave a Reply