I need to count a percentage change between two values.
The code I have here:
echo $time1
echo $time2
pc=$(( (($time2 - $time1)/$time1 * 100) ))
echo $pc
Brings such output in the console (with set -xe
option)
+ echo 1800
1800
+ echo 1000
1000
+ pc=0
+ echo 0
The code inside the math expression seems to be written properly, still, I get -80 or so. Why is this happening to me?
The second part of the question. I have no access and I will have no access to the bc command. From what I heard it can give me the absolute value of the number I have.
So.. Without the bc command - will this be a good idea for an IF condition?
if (( (( "$pc" > 20 || (( "$pc" < -20 )); then...