如图,万一我在please enter a position interger: 时候直接回车,我会得到许多
./practise_sum.sh: line 13: ((: 9691>: syntax error: operand expected (error token is “>”)
请问如何验证用户是不是输入了东西呢?
我的代码如下
#!/bin/bash
#
while true
do
read -t 30 -p "Please enter an integer: " input
if [ -n ${input//[0-9]/} ]
then
echo "Only integer is allowed."
else
index=1
sum=0
until (($index>$input))
do
sum=$(($sum+$index))
((++index))
done
echo "Sum for 1+2+...+$input is: $sum"
exit
fi
done