Case section:
#!/bin/bash //program starts #file: case.shecho "==========" echo "welcome!" echo "1 copy" echo "2 delete" echo "3 backup" echo "4 Quit" echo "= = = ======= "echo " Please input your select: "read n //Read input case $n in 1) echo "Your select is copy! " ;;     2) echo "your select is delete!" ;; 3) echo "your select is backup!" ;;     4) echo "your select is quit!" ;; *) echo "your select is invalid!" ;; esac //Program End
For section:
#!/bin/bash//program start #file:for.shfor N in 1 2 3 4 5//Turn N to loop assignment do echo ' The number is: $n ' done End of program
While section:
Print the square value of a natural number less than 10
#!/bin/bash//program start #file:while.shn=1while [$n-lt 10]//As long as n is less than 10 execute do squ= ' expr $n \* $n ' The N squared echo $squ//Output square value n= ' expr $n + 1 '//n gradually add 1 to match 10done//program knot Beam
The power value of print 2 is less than 100
#!/bin/bash//program start #file:var.shn=1while ["$n"-lt "] do echo" The value is: $n "N= ' ex PR $n \* 2 ' done//end of program
Print half a positive triangle
#!/bin/bash //program starts #file: interactive.shread -p "Please input a number:" num //reads the number of rows entered read -p "Please input a charsymbol: " sym //read into the displayed symbols a=1while [ $a -le $num ] //Outer Loop, A is less than or equal to the number of rows entered do b=1 //b represents the number of symbols printed while [ $b -le $a ] //the number of symbols printed is less than or equal to the number of lines do echo -n "$sym" //-n means no line break, print symbols b= ' expr $b + 1 ' // The number of symbols continues to increase to match a done echo //= NewLine a= ' expr $a + 1 ' // A constant increase to match the number of rows done //Program End
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/79/5E/wKioL1aPYMzCfCuZAADBuwpISbE242.jpg "title=" 11.jpg "alt=" Wkiol1apymzcfcuzaadbuwpisbe242.jpg "/>
Show results
The next half inverted triangle, positive triangle, the windmill continues to update!
This article from "Experience from pain" blog, declined reprint!
Shell---case, for, while