Answers for "how to perform mathematical operations in shell script"

1

arithmetic operation in bash

#!/bin/bash
x=5
y=10
ans=$(( x + y ))
echo "$x + $y = $ans"
Posted by: Guest on June-06-2020
0

how to perform mathematical operations in shell script

#!/bin/sh

a=10
b=20

val=`expr $a + $b`
echo "a + b : $val"

val=`expr $a - $b`
echo "a - b : $val"

val=`expr $a \* $b`
echo "a * b : $val"

val=`expr $b / $a`
echo "b / a : $val"

val=`expr $b % $a`
echo "b % a : $val"

if [ $a == $b ]
then
   echo "a is equal to b"
fi

if [ $a != $b ]
then
   echo "a is not equal to b"
fi
Posted by: Guest on June-25-2020

Code answers related to "how to perform mathematical operations in shell script"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language