【发布时间】:2021-03-09 13:28:23
【问题描述】:
嘿,伙计们,我正在尝试编写一个脚本来连续查找两个数字的乘积,例如 1*2 2*3 3*4 等...直到最大数字,但我在第 14 行不断收到此错误
./test.sh: line 14: ((: 2=1: attempted assignment to non-variable (error token is "=1")
并且不确定我做错了什么非常新的 bash 任何帮助将不胜感激。
#!/bin/bash
#A script to find the products of two nonnegative numbers in succesion to each other up to a maximum
number>
a=1
b=2
prod=$(($a*$b))
count=1
echo "Input The max number to find product of numbers in succesion with each other up to."
read maxnum
echo "Ok all the products of numbers in succesion to each other from 1 to" $maxnum "are as follows."
for (( $b=1; $b<=$maxnum; $bb++ ))
do
for (( $a=1; $a<$b; $a++ ))
do
for (( $count=1; $count<=$maxnum; ++$count ))
do
echo $count". "$prod
done
done
done
echo "You have now reached the end of your range of products with integers in succession to each
other"
【问题讨论】:
-
你能发布一个你的输入和预期输出的例子
-
初始设置后“prod”脚本将在哪里修改?
-
请先将您的脚本粘贴到shellcheck.net,然后尝试实施那里提出的建议。
-
所以基本上我正在尝试编写一个脚本,允许用户输入一个数字范围的最大数字,比如 10,然后程序将两个数字的集合连续相乘,直到像这样的给定范围 请输入范围 10 的最大数字 好的 从 1 到“$maxnum 的所有数字的连续乘积如下。1. 2 2. 6 3. 12 4. 20 5. 30 6 . 42 7. 56 8. 72 9. 90
-
请更新问题以包含所需的输出
标签: bash shell scripting git-bash