我正在写下面给出的命令。
if ["$avg" -ge "80"]; then
echo "PASS"
else
echo "FAIL"
我收到如下错误:
x.0000000000000000 integer expression expected
and the result of if -else statement is always wrong.
请提供帮助并建议必要的变更。
答案1
#!/bin/bash
# .........
# ........
if [ $avg -ge 80 ]
then
echo "PASS"
else
echo "FAIL"
fi
作为钢铁司机建议使用shellcheck
. 您可以使用以下方式安装
sudo apt install shellcheck
与以下产品一起使用
shellcheck myscript.sh
对于您来说,您将获得以下输出:
In myscript.sh line 1:
if ["$avg" -ge "80"]; then
^-- SC1009: The mentioned parser error was in this if expression.
^-- SC1035: You need a space after the [ and before the ].
^-- SC1073: Couldn't parse this test expression.
^-- SC1020: You need a space before the ].
^-- SC1072: Missing space before ]. Fix any mentioned problems and try again.