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