我正在创建一个小程序,做一些简单的数学运算,但不能运行它。它只是输出“意外的文件结尾”。我似乎找不到错误。。?
#!/bin/bash
until [ $second_num -ne 0 ]; do
echo "Enter number 1:"
read first_num
echo "Enter number 2:"
read second_num
echo "Cannot divide by 0. Start over."
done
result=0
if [ $first_num -ne 999 && $second_num -ne 999 ]; then
let result=$((first_num/second_num))
echo $result
echo "Program finished!"
else
echo "You have exited the program."
exit 0
fi
number=1
while [ $number -lt 100 ]; do
echo $number
let number=$(( $number % 5 ))
echo $number >> sample.txt
done
最佳答案
乍一看,你的剧本有两个问题:until [ $second_num -ne 0 ]; do
您没有初始化$second_num
,因此您试图将0与零进行比较。if [ $first_num -ne 999 && $second_num -ne 999 ]; then
&&
是一个conditional execution operator。方括号内两个表达式的AND运算符是-a
。
关于linux - bash文件中出现意外的eof错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15723641/