尝试运行脚本时出现语法错误

尝试运行脚本时出现语法错误

(standard_in) 1: syntax error我尝试在 bash 脚本中运行以下代码时遇到错误 ( )。有人可以指出我正确的方向吗?

if [[ $(bc <<< "$p0value > $freezeMax") ]]; then
        vP0='<a href="f1.php" class="blink">[Freezer 1: '
        vP0=$vP0$p0value
        vP0="$vP0 &deg;C]</a>"
        tempDIFF=$( bc <<< "$p0value-$freezeMax")
        echo "$P0_name is currently at $p0value °C, which is $tempDIFF °C higher than it should be. Please attend to this." >> $emailPATH/email.txt
        sendP0=1
elif [[ $(bc <<< "$p0value < $freezeMin") ]]; then
        vP0='<a href="f1.php" class="blink">[Freezer 1: '
        vP0=$vP0$p0value
        vP0="$vP0 &deg;C]</a>"
        tempDIFF=$(bc <<< "$freezeMin-$p0value")
        echo "$P0_name is currently at $p0value °C, which is $tempDIFF °C lower than it should be. Please attend to this." >> $emailPATH/email.txt
        sendP0=1
else
        vP0='<a href="f1.php" class="steady">[Freezer 1: '
        vP0=$vP0$p0value
        vP0="$vP0 &deg;C]</a>"
        sendP0=0
fi

仅供参考:变量包含浮点数,因此我需要使用它bc来进行计算。
额外信息:
我在运行 Raspbian Jessie 的 Raspberry Pi 2 上运行此程序。
舍邦是#! /bin/bash

答案1

该错误来自bc,而不是运行脚本的 shell。也许其中一个变量为空?

 ~ $ bc <<< " < 1"
(standard_in) 1: syntax error

答案2

公元前将输出1 如果条件为真

测试应该是

if [ $( bc <<< "test" ) == 1 ]

阅读有关的手册页[[表明这将测试字符串的长度,这可能不是您想要的。

相关内容