Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8510633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:45:32+00:00 2026-06-11T03:45:32+00:00

I am testing if a variable is greater than another variable. The if evaluation

  • 0

I am testing if a variable is greater than another variable. The if evaluation is getting the same value no matter what the values are.

COMP(){
avg=$(for avg in $(for file in $(ls /var/log/sa/sa[0123]*); do echo $file; done); do sar -r -f $avg| tail -1; done | awk '{totavg+=$4} END {print (totavg/NR)*5}');
for comp in $(sar -r -f /var/log/sa/sa08 | egrep -v "^$|Average|CPU|used" | awk '{print $5}'); do
        if [ `echo $avg` <  `echo $comp` ];
                then echo 'You have had a spike!';
                echo "COMP = $comp";
                echo "AVG = $avg";
        fi;
done }

I am getting this output even though the values are not really evaluating to true.

You have had a spike!
COMP = 41.20
AVG = 145.438
You have had a spike!
COMP = 41.20
AVG = 145.438
You have had a spike!
COMP = 41.19
AVG = 145.438
You have had a spike!  
COMP = 41.24 
AVG = 145.438

I have tried this multiple ways but can not get it working. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:45:33+00:00Added an answer on June 11, 2026 at 3:45 am

    yep as ingnacio has pointed out

    average=`echo $avg`;
    comp1=`echo $comp`
    
      if ((average)) 2>/dev/null; then
         average=$((average))
       else
         average=0;
      fi
     if ((comp1)) 2>/dev/null; then
         comp1=$((comp1))
      else
         comp1=0;
      fi
    
    if [ $average -lt $comp1 ];then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the expected behaviour when testing a non-existing variable in a jsp file
I have a variable patt with a dynamic numerical value var patt = %+number+:;
i have this variable. $productId = 2; // Testing ID $value->id; // Contains INT
Testing.BSMain, Text: Start Page I would like to substring the value above and returning
In testing an app, I keep getting errors that occur sporadically on only one
Im stuck, Im setting a variable when someone clicks, then testing with if to
I have a Unit testing problem where a class has a static variable which
I am having difficulties testing window.setInterval function in my Javascript file. Below is the
From the isset() docs : isset() will return FALSE if testing a variable that
How can I assert that a variable satisfies any one of two values in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.