-6

We have two values

$a
$b

we need to compare the $a value with $b value

in case $b value is less than ($a - 3) or more than ($a + 3), then it will print fail.

example:

a=10
b=14

then it should fail.

For:

a=10
b=11

then it's ok.

For:

a=23
b=6

then it should fail.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
yael
  • 13,106

2 Answers2

1

I can't quite work out what exact numerical comparison you want to make, but in general in Bash arithmetic can be done as follows:

#!/bin/bash
a=100;
b=200;
threshold=50;

if [ $(($b - $a)) -gt $threshold ]
then
   echo Something.
else
   echo Something else.
fi
Edward
  • 2,509
0

Use bash arithmetic:

if (( (a-b) > 3 )) || (( (b-a) > 3 )); then
  echo fail
fi

Based on @ctrl-alt-delor's guess.

FedKad
  • 610
  • 4
  • 17