0

为什么 if-compression 不比较值?

idle_time=exec sudo -u home xprintidle

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

它不是那样工作的

4

1 回答 1

0

首先,我更改为您用于以不同用户身份执行 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
于 2018-08-10T09:25:14.827 回答