【发布时间】:2021-03-18 16:21:49
【问题描述】:
请帮助我下面的shell程序给我以下结果
Solution.sh: line 7: 3..1184: syntax error: invalid arithmetic operator (error token is "..1184")
Solution.sh: line 10: 3..1210: syntax error: invalid arithmetic operator (error token is "..1210")
read a
read b
c=0
d=0
for i in 1 2 3..$a
do
if [[ $(( $a % i )) == 0 ]]
then
c=c+i
fi
done
for j in 1 2 3..$b
do
if [[ $(( $b % j )) == 0 ]]
then
d=d+i
fi
done
if [[ $a == $d && $b == $c ]]
then
echo "The pair is amicable"
else
echo "The pair is not amicable"
fi
【问题讨论】:
-
我不确定
for i in 1 2 3..$a能否正常工作。试试for i in {1..$a}? -
还有许多其他问题。首先通过shellcheck.net运行您的脚本
-
@r3mainer 是正确的,那是行不通的....顺便说一句,友好的数字分配在哪里完成-这是几天内的第三个……和 IIRC扔掉任何与一个配对的东西(因为数字不是答案的一部分 - 所以逻辑是错误的。
-
@Mr R 正在进行一项测试 unix 技能的评估,这就是您看到这些问题的原因。