<分区>
我需要我的表达式能够根据输入求解下一个可被 15 整除的区间。
(还)不是一个很好的编码器。尝试了很多 (( 和 [[ 以及类似的变体,但我觉得代码的编写方式是错误的。
printf "Enter a number: "
read DVSBL
let ISDIV=$DVSBL
if [ $(( $ISDIV % 15 )) -eq 0 ]; then
echo $DVSBL is divisible by 15.
elif [[ $(( $ISDIV % 5 )) -eq 0 && $(( $ISDIV % 15 )) -ne 0 ]]; then
echo $DVSBL is divisible by 5 and not by 15.
elif [[ $(( $ISDIV % 3 )) -eq 0 && $(( $ISDIV % 15 )) -ne 0 ]]; then
echo $DVSBL is divisible by 3 and not by 15.
#from and below is where i am having the most trouble
else let NXTCLS=$NXTCLS
$NXTCLS='(( $ISDIV / 15 ) + 1) * 15
echo The next closest number to $DVSBL that is divisible by 15 is $NXTCLS
fi
在 if 语句中一切正常,但在尝试解决最后几行的错误时,我放弃了我最初的想法并且偏离了解决这个问题的距离。