Script Programming Control Structure:
Order
Select: If, case
Loops: For, while, until
For variable in List;do
Statement
Done
For ((CONDITION));d o
Statement
Done
While Condition;do
Statement
Done
Until Condition;do
Statement
Done
Loop Example: Test whether all hosts between 192.168.80.1 to 192.168.80.80.255 are online through the ping command, and if online, "IP is up.", where the IP address is replaced with a real IP address and displayed in green; IP is down. ", where the IP address is replaced by a real IP address and displayed in red. (implemented using while,until,for loops, respectively)
Note: Echo Output color-e (enable interpretation of backslash escapes)
\e or \ 033来 output ESC symbol
Format color:\e[background color; highlight m Restore defaults to \e[0m
\033 [background color; foreground colour; highlight m restore defaults to \033[0m
First parameter:
0 transparent (using terminal color), 1 highlight 40 black, 41 red, 42 green, 43 yellow, 44 blue 45 Violet, 46 cyan
Green, 47 white (grey)
A second parameter:
The foreground color (that is, the colour of the text) can be replaced by the following numbers
30 Black 31 Red, 32 green, 33 yellow, 34 blue, 35 violet, 36 turquoise, 37 white (grey)
A third parameter:
Highlight is 1, not highlight is 0
The fourth parameter is m:
Extended bat script in the For loop example:
Example one reading a file
@echo off
for/f%%i in (test.txt) does ping%%i-n 2-w 2 > Nul && echo%%i up | | Echo%%i Down
Pause
Example two reading a number
@echo off
FOR/L%%i in (1,1,255) does ping%%i-n 2-w 2 > Nul && echo%%i up | | Echo%%i Down
Pause
This article is from the "Wine" blog, please be sure to keep this source http://knowledge92.blog.51cto.com/7143076/1677008
Shell-Loop Statements