Shell script: Print 99 multiplication table

Source: Internet
Author: User

Shell script: Print 99 multiplication table

Today in three different ways to achieve the shell script Print 99 multiplication table, the code is as follows

Method 1: Use a For loop (a.sh)

#!/bin/shfor i in {1,2,3,4,5,6,7,8,9}do to  J in {1,2,3,4,5,6,7,8,9}  do    ((product= $i * $j))    Echo-ne $i \ * $j = $product "\ t" done  echodoneexit 0

Method 2: Use the While loop (b.sh)

#!/bin/shi=1j=1while ["$i"-ne]do while  ["$j"-ne] do    ((product= $i * $j))    echo-ne $i \* $j = $product "\ T"    ((j + +)) done  j=1  ((i++))  Echodoneexit 0

Method 3: Use a For loop (c.sh)

#!/bin/shfor ((i=1;i<10;i++)) does   ((j=1;j<10;j++)) do    ((product= $i * $j))    echo-ne $i * $j = $product "\ t" done  echodoneexit 0

Note: the command "Echo-ne XXX", the parameter n means the output is complete without wrapping, E for the support of escape characters

Three scripts to run:

END

    • Related articles recommended:
    • Linux shell scripts enable FTP to automatically upload backup files
    • Input and output redirection for Linux shell programming
    • How to pass a variable to awk in a shell script
    • This article from: Hobby Linux Technology Network
    • This article link: http://www.ahlinux.com/shell/9142.html

Shell script: Print 99 multiplication table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.