shell脚本while99乘法表
时间: 2023-11-20 20:58:34 浏览: 41
以下是使用while循环打印九九乘法表的Shell脚本:
```shell
i=1
while [ $i -le 9 ]
do
j=1
while [ $j -le $i ]
do
echo -n "$i*$j=$(($i*$j)) "
j=$(($j+1))
done
echo ""
i=$(($i+1))
done
```
该脚本中使用了两个while循环,外层循环控制行数,内层循环控制列数。在内层循环中,使用`echo -n`命令输出不换行的乘法表内容,使用`$(($i*$j))`计算乘积。在内层循环结束后,使用`echo ""`命令输出一个空行,以便下一行的输出。
相关问题
shell脚本求九九乘法表
以下是两种shell脚本实现九九乘法表的方法:
1. 第一种实现方式:
```shell
#!/bin/bash
for i in `seq 1 9`
do
for j in `seq 1 9`
do
if [ $i -le $j ]
then
echo -en "$i*$j=$(($i*$j))\t"
else
echo -en "\t"
fi
done
echo
done
```
2. 第二种实现方式:
```shell
#!/bin/bash
for((i=1;i<10;i++))
do
for((j=1;j<10;j++))
do
if [ $i -le $j ]
then
echo -en "$i*$j=$(($i*$j))\t"
else
echo -en "\t"
fi
done
echo
done
```
利用shell脚本写九九乘法表
以下是一个用shell脚本编写九九乘法表的示例:
```bash
#!/bin/bash
for i in {1..9}
do
for j in {1..9}
do
let "result=i*j"
echo -n "$i*$j=$result "
done
echo ""
done
```
该脚本使用了两个嵌套的for循环来遍历九九乘法表中的所有数字,并使用echo命令输出每个数字的乘积。其中,“-n”选项用于在输出的末尾不添加换行符,以便在同一行上输出多个结果。最后,第二个echo命令用于在每一行的结尾添加一个换行符,以便在下一行上输出下一组结果。