99 multiplication table of shell programming

This is a shell script training program, mainly to practice the use of for-in loop

#!  /bin/bash

for i in `seq 1 9` #The outer loop is responsible for printing the line... Note that `seq 1 9` is enclosed in backticks (not single quotes), indicating command substitution

do 

     for j in `seq 1 $i` #The inner loop is responsible for printing columns... In shell scripts, when using variables, you need to add a $ sign before the variable name

     do #The boundary of the loop body, described by do and done

           echo -ne ''$j*$i=$[$j*$i]\t" #$ is connected with [], which means arithmetic operation...because \t is an escape character, -e is needed, -n means cancel line feed (requires "striking")

     done

     echo #The role of this echo: After each memory cycle ends, a newline is performed (echo defaults to a newline)

done

 

Script execution effect

command execution effect

 

Script description:

There are two types of for statements in shell scripts:
one is a "traverser" (that is, a for-in loop), which is similar to the foreach statement in java. Before executing the loop, there must be a set. The process of loop execution is the process of variable set elements. ... This article introduces this
kind of "automatic machine", which is similar to the for loop in C language, and needs to describe the boundary and step size of the loop ... Next time I will introduce it

 

 

 

 

 

 

 

     

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325125260&siteId=291194637