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

1 Answers1

1

For floating point arithmetic you can use awk:

awk -v s="$usep2" 'BEGIN{if (s < 0.1) print s}'
anubhava
  • 761,203
  • 64
  • 569
  • 643