Bash:整数表現が必要です。

Bash:整数表現が必要です。

最近操作が中断されました。コードで変更する必要があることをご存知ですか?

TIME=`grep real < /tmp/EV_Check.time | cut -d ' ' -f2`
time=$TIME
test $time -ge $ct
result=$?
        if [ "$result" -eq "1" ]
        then
        crit=1
        msg="Report execution takes $time!"
        fi
test $time -ge $wt
result=$?
        if [ "$result" -eq "1" ]
        then
        warn=1
        msg="Report execution takes $time!"
        fi

if [ $crit -eq 1 -a $warn -eq 0 ]
then
       echo "Critical value must be greater than warning value !"
       help_usage
       exit 3
fi

次のエラーが発生します。 -

./check_ev_report.sh: line 158: test: 0.45: integer expression expected
./check_ev_report.sh: line 166: test: 0.45: integer expression expected
OK - 0.45

ベストアンサー1

bashは整数演算のみ実行できます。

浮動小数点値を比較するには、外部ツールを呼び出す必要があります。bc

if [[ $(bc <<<"$time >= $ct") == "1" ]]; then
    do_something
fi

おすすめ記事