Я пытаюсь записать простую веб-страницу на пи малины с Помощником Ubuntu 16.04.
Существует что-то не так с этими сравнениями, поскольку, где ctemp равняется 31 или любой другой температуре, я получаю сообщение, "Я понятия не имею, какова температура".
Я думаю, что мои сравнения выключены, но я, может казаться, не выясняю, как получить надлежащее сравнение.
#!/bin/bash
echo "<html><body>"
#get temp too and show in images
sensor=`/opt/vc/bin/vcgencmd measure_temp | sed "s/[^0-9]//g"`
#sensor is 10 times higher than actual Core temp.
ctemp=$((sensor/10))
echo "Core Temp: " $ctemp
if [ "$ctemp" >= "20" ] && [ "$ctemp" < "38" ];then
echo "<img src=\"cool.png\" alt=\"cool\">"
elif [ "$ctemp" >= "38" ] && [ "$ctemp" < "50" ];then
echo "<img src=\"mid.png\" alt=\"Normal Operational Temprature\"><br>"
elif [ "$ctemp" >= "50" ];then
echo "<img src=\"hot.png\" alt=\"Hot\">"
else
echo "<br>I have no clue what temprature it is<br>"
fi
От man bash
:
string1 == string2
string1 = string2
True if the strings are equal. = should be used with the test
command for POSIX conformance. When used with the [[ command,
this performs pattern matching as described above (Compound
Commands).
string1 != string2
True if the strings are not equal.
string1 < string2
True if string1 sorts before string2 lexicographically.
string1 > string2
True if string1 sorts after string2 lexicographically.
arg1 OP arg2
OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic
binary operators return true if arg1 is equal to, not equal to,
less than, less than or equal to, greater than, or greater than
or equal to arg2, respectively. Arg1 and arg2 may be positive
or negative integers.
Так, вместо того, чтобы соответствовать >=
и <
(сравнение строк), использование -ge
и -lt
(числовое сравнение).