#!/bin/bash # Crushlinux # 2017-03-10 for one in {1..9} do for ((two=1;two<=$one;two++)) do echo -n "$two x $one = $(($one*$two)) " done echo done
版本二:
#!/bin/bash #99乘法表 for i in {1..9} do for j in {1..9} do echo -n "$j*$i=$(expr $j * $i) " if [ $j == $i ];then echo -e ' ' #-e 允许对后面做出解释 break fi done done
版本三:
#!/bin/bash for i in {1..9} do for j in {1..9} do if [ $j -le $i ] then echo -n "$j x $i = $(($j*$i)) " fi done echo done