shell 九九乘法表

for i in {1..9}; do
    for ((j = 1; j <= i; j++)); do
        count=$((j * i))
        if [[ "$i" == "$j" ]]; then
            printf "%s*%s=\e[1;36m%s\e[0m\n" "$j" "$i" "$count"
        else
            printf "%s*%s=\e[1;36m%s\e[0m\t" "$j" "$i" "$count"
        fi
    done
done

输出示例

iShot_2022-08-08_11.05.22.png

#!/bin/bash
# 9*9 乘法表(编写 shell 脚本,打印 9*9 乘法表) 
for i in $(seq 9); do
    for j in $(seq "$i"); do
        echo -n -e "$j*$i=$((i * j))\t"
    done
    echo
done