我从我的脚本中获取的一些代码:
hh=$(bc -l <<< "scale=5; $h2-$h1")
delta=$(abs $hh)
echo "delta h = $delta"
for (( i=0; i <= ( ${#arr0[@]} - 1); i++ )); do
if [ $delta > 0.03000000000000000000 ] && [ ${arr1[$i]} > 100 ] then
echo "attack Ddos"
iptables -A INPUT -s 192.168.162.1 -j DROP
break
else
echo "No attack Ddos"
fi
done
其输出:
delta h = .05526800237680984201
./trung1 (copy): line 115: syntax error near unexpected token `else'
./trung1 (copy): line 115: ` else'
如何解决此错误?
答案 0 :(得分:3)
then
之前需要一个分号。在这方面,if-then
与for-do
的工作方式相同。
答案 1 :(得分:2)
您只是在if
声明后错过了分号:
hh=$(bc -l <<< "scale=5; $h2-$h1")
delta=$(abs $hh)
echo "delta h = $delta"
for (( i=0; i <= ( ${#arr0[@]} - 1); i++ )); do
if [ $delta > 0.03000000000000000000 ] && [ ${arr1[$i]} > 100 ] ; then #There is either a semi-colon here, or a new line
echo "attack Ddos"
iptables -A INPUT -s 192.168.162.1 -j DROP
break
else
echo "No attack Ddos"
fi
done