【问题标题】:bash script: getting idle time and compare itbash 脚本:获取空闲时间并进行比较
【发布时间】:2019-01-17 19:05:40
【问题描述】:

为什么if-compression不比较值?

idle_time=exec sudo -u home xprintidle

if [ "$idle_time" -ge 6000 ]
  then
  echo "hi"
fi

它不是那样工作的

【问题讨论】:

    标签: bash sh idle-processing


    【解决方案1】:

    首先,我更改了用于以不同用户身份执行 xprintidle 的行。 之后我调整了 if 子句,因为也有错误。

    #!/bin/bash
    # actually assign the variable
    idle_time=$(idle_time=exec sudo -u home xprintidle)
    # adapted if clause to actually match (see https://stackoverflow.com/questions/18668556/comparing-numbers-in-bash) 
    if [ "$idle_time" -gt "6000" ]; then
        echo "hi"
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2014-07-21
      • 2020-07-12
      • 1970-01-01
      相关资源
      最近更新 更多