【发布时间】:2021-03-18 10:07:29
【问题描述】:
a=0
b=0
numterms=0
echo -e -n "\nEnter a number for variable a: "
read a
echo ""
echo -e -n "\nEnter a number for variable b: "
read b
echo ""
echo -e -n "\nEnter a number for how many terms printed: "
read numterms
echo ""
n=1
numtermss=$(($numterms+1))
while [ $n -lt $numtermss ]
do
sum=$(($a * $n + $b))
n=$(($n + 1))
echo $sum
if [ $numterms -lt 0 ]
then
echo -e -n "Number needs to be postive."
echo ""
else
echo -e -n "\nEnter another number for variable a: "
read aa
echo ""
echo -e -n "n\Enther another number for variable b: "
read bb
echo ""
echo -e -n "n\Enter another number for amount of terms: "
read terms
echo ""
aa=0
bb=0
terms=0
for i in "$@"
do
number=(head -1 "$i")
bb=$((bb+1))
aa=$((aa + number))
termss=$(($terms+1))
echo " The sum is $aa"
fi
done
我试图让 bash 代码创建一个线性序列,其中用户输入变量 a、b 以及应该输出多少项。 U=a(n)+b 然后为同一线性序列选择其他变量并输出计数之和。
【问题讨论】:
-
使用shellcheck.net。此外,您可以尝试删除(/注释掉)代码部分以找出问题的来源。
-
您似乎缺少内部循环的“完成”。
number=(head缺少$。