shell for循环练习题99乘法表

#!/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 '\n'    #-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

  

转载于:https://www.cnblogs.com/crushlinux/p/6738320.html

你可能感兴趣的:(shell for循环练习题99乘法表)