shell script combat - print multiplication table

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_25908839/article/details/86548003

Objective: To print the multiplication table

Ideas: the use for loop, the outer loop print line, the print column loop

Demo.sh create a script file, enter the following code

#!/bin/bash
#Date:        2019.01.18
#Author:    TURF
#Mail:        [email protected]
#Function:    print multiplication table
#Version:    1.0

$ I in for (SEQ. 9);
do 
    for J in $ (SEQ $ I);
    do
        echo -ne "$ * $ I $ J = (($ I $ J *)) \ T"; # $ (() ) may be a simple basic operation, and returns the result
    DONE;
    echo
DONE;

In the terminal command execution $ bash demo.sh    

result:

turf96 @ turf96: / media / turf96 / Documents / all of the e-book / shell script Raiders / shell script combat / bash demo.sh 1 print multiplication table $
1 * 1 = 1    
2 * 1 = 2 = 2 * 2 4    
3 * 1 = 33 * 2 = 63 * 3 = 9    
4 * 1 = 44 * 2 = 84 * 3 = 124 * 4 = 16    
5 * 1 = 55 * 2 = 105 * 3 = 155 * 4 = 205 * 5 = 25    
6 * 1 = 66 * 2 = 126 * 3 = 186 * 4 = 246 * 5 = 30 6 * 6 = 36    
7 * 1 = 77 * 2 = 147 * 3 = 217 * 4 = 287 * 5 = 357 * 6 = 42 7 * 7 = 49    
8 * 1 = 88 * 2 = 168 * 3 = 248 * 4 = 328 * 5 = 408 * 6 = 488 * 7 = 568 * 8 = 64    
9 * 1 = 99 * 2 = 189 * 3 = 279 * 4 = 369 * 5 = 459 * 6 = 549 * 7 = 639 8 * 9 * 9 = 72 = 81    
 

Guess you like

Origin blog.csdn.net/qq_25908839/article/details/86548003