Shell Programming 9*9 Multiplication Table

Source: Internet
Author: User
Tags arithmetic echo command

</pre> script content <pre name= "code" class= "plain" >#!/bin/bashfor I in "1" "2" "3" "4" "5" "6" "7" "8" "9" do  &nbsp ;      for J in "1" "2" "3" "4" "5" "6" "7" "8" "9"                 do                        IF [${j}-lt  ${i}]    &nbs P                    then                                        k=$ ((i * j))       &NBS P                                 Echo-n ${ i}*${j}=${k}$ ' \ t '                         fi    &NBSP ;                   IF [${j}-eq ${i}]          &NBS P   &NBSP          then                                        k=$ ((i * j))                 &NBS P                       echo   ${i}*${j}=${k}    &NBSP ;                   fi                D Onedone
Output results


Summarize the points of knowledge

1. For loop

For v_1 in [list]

Do

Done

List if it is "1 2 3", then the V_1 value is an array 1 2 3

If you want to assign only one value to v_1 at a time, you need to write separately, i.e. "1" "2" "3"

2. Arithmetic operations in Bash

k=$ ((i * j))

There must be no spaces around the equals sign, no spaces for assignment.

In addition, the arithmetic operation needs to be enclosed in $ (()), which means that the operation is performed first and the result is calculated. Operator subtraction with spaces on both sides.

3. Use of the echo command

Echo, output the character following echo.

The default output is followed by a line break.

The-n parameter cancels the line break at the end.

The-e parameter enables the escape character to take effect. The escape character is "\" and the usual escape character is \ \ t \ n

Example: Echo-e 1\\t2

Echo-ne 1\\n2


Shell Programming 9*9 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.