A Bash Script: A while loop in the Loop Structure
Like other languages, the Bash loop structure also contains the while statement.Basic Structure
While condition do loop body done
Like the for statement, its loop body is also do... Done structure.
First, Introduction
In shell programming, circular commands are used to control the execution of certain statements under certain conditions, with three commonly used loop statements: for, while, and until. While loops and for loops belong to the
First, using the For loop structureTarget:This case requires writing a shell script chkhosts.sh that uses a for loop to detect the surviving status of multiple hosts, with the following requirements and instructions:1> Ping Detection of 192.168.4.0/2
Theoretical part:The loop means that the program executes some statements repeatedly;Whiler loop is a kind of cyclic structure, when it is not known in advance how many times the loop executes, it is necessary to use the while loop; while the
One, while loop
The while loop is used to continuously execute a series of commands and to read data from an input file; a command is usually a test condition. The format is:
Copy Code code as follows:
While command
Todo
Command1
1 for LoopSyntax: for variable name in condition; ; doneExample 1#!/bin/bashsum=0for i in `seq 1 100`;dosum=$[$sum+$i]doneecho $sumExample 2Find all files with the suffix. txt in the/123 directoryBulk Modify. txt to. txt.bakAnalysis:There are two
1, for: Read different variable values, execute the same set of commands one by one, until the value is complete exit, variable values are separated by a spaceGrammar:For variable value in value listDoCommand sequenceDone2, while: Repeated testing a
A while loop in PHP that iterates through the number of code block attempts, or loops through code blocks when the specified condition is true.
-------------------------------------------------------------
When we write code, we often need a block
Shell script loop for while until and package management "on"Loop executionTo run a code segment repeatedly multiple timesHow many times to run repeatedly:Number of cycles known beforehandNumber of cycles unknown beforehandThere are entry conditions
Directory:I. While loop and until loopTwo. Loop control statement continue break shiftThree. Special usageI. While loop and until loop
1.while CycleWhile CONDITION; DoLoop bodyDoneCONDITION: cyclic control condition; Before entering the loop,
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.