收到“文件意外结束”错误

收到“文件意外结束”错误

我收到一条错误消息,提示第 44 行:语法错误:文件意外结束

#!/bin/sh


touch $results.txt #creates txt file

now="$(date)" #records current date and time to be posted

echo "Name: Kevin Delrisco" > results.txt

echo "Date and time: $now" >> results.txt

echo -n "Enter a number between 1-50: " # asks user to enter a number

read n

while [[$n -le 1 || $n -ge 51 ]] do #while loop to check if number is over 50


        echo -n "Enter a number between 1-50: "

        read n; 
done

sum= 0

for (( i = 1; i<=$n; i++ )) do #for loop to add the sum

        sum=$(( $sum + $i ));
done

echo "Sum of numbers is $sum"
echo "Sum of numbers is $sum" >> results.txt

答案1

read n done

这将从输入中读取两个值到$n$done

在之前插入;或换行符done以使其关闭 while 循环。

相关内容