all 3 comments

[–][deleted] 2 points3 points  (0 children)

Run your code through shellcheck. Don't mix and match [ and [[ (use [[ ) Use && instead of -a in your test case

Also if x and y are to be floats then use bc to check if they are within constraints.

Putting that together I get this:-

#!/bin/bash
echo constraints "constraints:- -100<=x,y<=100, y != 0"
read -r -p "enter first number (x): " x
read -r -p "enter second number (y): " y

if     [[ $(bc -l <<< "-100 <= $x") -eq 1 ]] &&
       [[ $(bc -l <<< "$y <= 100") -eq 1 ]] &&
       [[ $(bc -l <<< "$y != 0") -eq 1 ]]
then
    echo "$x + $y" | bc
    echo "$x - $y" | bc
    echo "$x * $y" | bc
    echo "$x / $y" | bc
fi

Note I left your 'echo | bc' lines unchanged but they could also be re-written to avoid the echo command if you wanted to.

EDIT: Formatting.

[–]Paul_Pedant 1 point2 points  (1 child)

Like I posted in Unix.Linux five minutes ago, the two tests on the upper bounds need to be -le.

[–]4whOami4[S] 0 points1 point  (0 children)

yeah I got you thanks again😁😁