I. Experimental requirements:
- Given any one of the characters N (n>0), then print the reverse multiplication table of the NXN.
two. Problem solving :
#/!bin/bash
#
#define Function
Nxn_fun () {
Local i=$1 #定义一个局部变量i控制外层循环
While [$i-ge 1];d o
Local j= $i #定义一个局部变量j控制内层循环
While [$j-ge 1];d o
ECHO-E-N "$i * $j =$[i*j]\t"
Let j--
Done
echo #换行
Let i--
Done
}
#main
Flag=$ (echo "$" | sed ' s/[0-9]//g ' | wc-c) #判断脚本参数是整型还是字符
if [! $#-eq 1];then #判断脚本参数个数
echo ">_<| | | It's awkward ~!!! usage:$ (basename) num. "
Exit 5
elif [! $Flag-eq 1];then #Flag值不等于1则给定的脚本参数为字符型
echo ">_<| | | It's awkward ~!!! usage:$ (basename) num. " #表情符号还是挺不错的
Exit 5
Fi
Nxn_fun $
[$?-eq 0]&&echo "Print $1*$1 multiplication table complete (^_^) hehe" | | echo "Function execution error, please check ... (B_d) Wearing a pair of glasses " #函数执行成功则打印乘法表
Three. Experimental results:
Four. Experimental thinking?
1. How can I tell if the parameters given by the script are characters or integers, there is no other way?
2. The outer while loop parameters can be directly to $, how to change, can't why?
Five. The comforting code snippet is:
Flag=$ (echo "$" | sed ' s/[0-9]//g ' | wc-c)
Print Reverse nxn multiplication table