#!/bin/bash
while true
do
read -p "Pls input a positive number: " num
expr $num + 1 &> /dev/null
if [ $? -eq 0];then
if [ expr $num > 0
-eq 1 ];then
for ((i=1;i<$num;i++))
do
sum=expr $sum + $i
done
echo "1+2+3+…+num=num=num=sum"
exit
fi
fi
echo "error,input enlegal"
continue
done
执行以上命令一老报错,报错如下:
Pls input a positive number: 3
expr_1.sh: line 8: [: missing `]'
error,input enlegal
请问是哪里出错了?