5

My shell is bash and I have three variables x=5; y=7; z=7.5

I am trying to use the below statement to test the equality of variables $y and $z as shown below

Command: test $z -eq $y; echo $?

But, it shows the following error and I am not able to resolve it.

-bash: test: 7.2: integer expression expected

2

Note: when I apply the same test command on integers $x and $y, they work fine.

AngiSen
  • 207

1 Answers1

5

You can use the == operator of bc.

test "$(echo $x == $z |bc)" -eq 1

expr1 == expr2
The result is 1 if expr1 is equal to expr2.

-- from man bc(1)

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
mjy
  • 596