-1

So I'm curling a json file and parsing it. The result is a number. Each one of these functions outputs a different number. I want the output in a Math equation, that's gonna go in IF statements.

function func() {
    curl -Ss -H 'Cache-Control: no-cache' url.com | jq -r '.[] | .[] | 
.interger'
}
function func2() {
    curl -Ss -H 'Cache-Control: no-cache' url.com | jq -r '.[] | .[] | 
.interger'
}
function func3() {
    curl -Ss -H 'Cache-Control: no-cache' url.com | jq -r '.[] | .[] | 
.interger'
}


if func*func2*func3 / func2*func3*func -ge 1
then
echo "yay"
fi
if func*func2*func3 / func2*func3*func -lt 1
then
echo "nay"
fi

Currently It is not doing any type of multiplication or division on the if statement, therefore making statement obsolete.

So far I've tried:

if [func*func2*func3 / func2*func3*func -ge 1]
then
echo "yay"
fi
if [func*func2*func3 / func2*func3*func -lt 1]
then
echo "nay"
fi

2 Answers2

1

Arithmetic is done with ((...)). Capturing output is done with $(...).

if (($(func)*$(func2)*$(func3) / $(func2)*$(func3)*$(func) >= 1)); then
    echo "yay"
fi
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
0

Try this:

if [[ $(( $(func) * $(func2) * $(func3) )) -gt 1 ]]; then
  echo yay
else
  echo nay
fi

The $(func) calls substitute the value in the command; the $(( ... )) performs arithmetic evaluation.

PhilR
  • 5,375
  • 1
  • 21
  • 27