【发布时间】: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
为什么if-compression不比较值?
idle_time=exec sudo -u home xprintidle
if [ "$idle_time" -ge 6000 ]
then
echo "hi"
fi
它不是那样工作的
【问题讨论】:
标签: bash sh idle-processing
首先,我更改了用于以不同用户身份执行 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
【讨论】: