Shell-Loop Statements

Source: Internet
Author: User

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

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.