[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

HELP!! Having trouble with bash script - need quick response

Here's where I'm stuck

temphigh=$(cat $d/temphigh | sed 's/ //g');
templow=$(cat $d/templow | sed 's/ //g');
actualtemp=$(cat $d/temperature | sed 's/ //g');

I have the sed part in there because the file has leading spaces:

temphigh=80.124
templow=20.212
actualtemp=55.129

What I can't get is I need to compare the actualtemp to temphigh and templow

But how do I compare these values - when -lt and -gt needs integer??





0
Tigger996
Asked:
Tigger996
  • 3
  • 2
1 Solution
 
ozoCommented:
if perl -e 'exit ( (shift) < (shift)); '  $temphigh $templow ; then  echo low ; fi
0
 
Tigger996Author Commented:
I'm pretty new to this - I don't quite understand that script

0
 
ozoCommented:
if awk "BEGIN{ exit $temphigh < $templow }" ; then echo high ; fi
0
 
Tigger996Author Commented:
Thanks for your code: I used the awk one but how come the logic is backwards.  Because logically if actualtemp is < templow shouldn't it echo low not high?  It works if I do it backwards.  But just wondering why it is like this.

0
 
ozoCommented:
Because of the convention that a 0 exit value is used for a success, and a non-zero exit value is used to indicate a failure.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now