0

how to use decimal condition check with IF STATEMENT. below program gives an error while checking the if condition.


#!/bin/sh usep=$(uptime | awk '{ print $10 }') usep1=$(echo $usep | awk '{ print $1}' | cut -d'%' -f1)`enter code here` usep1=${usep1%/} usep2=${usep1%,} # Remove "," echo $usep2 if [ $usep2 <= 0.1 ]; then echo $usep2 fi 
2
  • Use -le for comparing numbers not <= Commented Jun 24, 2014 at 18:33
  • Sorry, ignore that if floats. Commented Jun 24, 2014 at 18:34

1 Answer 1

1

For floating point arithmetic you can use awk:

awk -v s="$usep2" 'BEGIN{if (s < 0.1) print s}' 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.