In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what the while until of the BASH cycle refers to. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
You must be very familiar with loops, almost all programming will involve loops, this article will talk to you about the loop structure while, until in shell.
Shell cycle: the number of while until cycles is not necessarily fixed, can be fixed, can not be fixed
If you want to process a file line by line, it is recommended to use a while loop instead of a fot loop in the format of while read line;do;done
The number of processing cycles is fixed using for loops, and if the number of loops is not fixed, use while or until
Wait commands are executed after waiting for other commands to be executed, and are limited to daemons only.
1.while statement structure while conditional test
Do
Cyclic body
Done
When the conditional test is true (if the conditional test is true, the loop body is executed)
Until conditional Test of 2.until Grammar structure
Do
Cyclic body
Done
When the conditional test is established (the conditional test is false), execute the loop body
3. Instance 3.1while implements batch user creation of #! / bin/bash while read line do user=$ (echo "$line" | awk'{print $1}') pass=$ (echo "$line" | awk'{print $2}') if [${# user}-eq 0]; then continue fi id $user & > / dev/null if [$?-eq 0] Then echo "$user already exists..." Else useradd $user echo "$pass" | passwd-- stdin $user & > / dev/null if [$?-eq 0]; then echo "$user is created..." Fi fi done $1 12345678910111213141516171819203.2while to test the connection to the host when the host can ping general rules do not output, when the host down then output
#! / bin/bash ip=192.168.81.10 while ping-C1-W1 $ip & > / dev/null do sleep 1 done echo "$ip is down" 12345673.3until to test the connection to the host does not output when the host ping is different, but when the host up
#! / bin/bash ip=192.168.81.10 until ping-C1-W1 $ip & > / dev/null do Sleep 1 done Echo "$ip is up" 12345673.4for loop implements host detection #! / bin/bash for i in {1... 254} do {ip=192.168.81.$i ping-C1-W1 $ip & > / dev/null if [$?-eq 0] Then echo "$ip" fi} & done wait echo "all finish." the 12345678910111213143.5while loop implements host detection #! / bin/bash iTunes 1 while [$I-le 254] do {ip=192.168.81.$i ping-C1-W1 $ip & > / dev/null if [$?-eq 0] Then echo "$ip" fi} & let iTunes + done wait 1234567891011121314153.6until implements host detection #! / bin/bash iTunes 1 until [$I-gt 254] do {ip=192.168.81.$i ping-C1-W1 $ip & > / dev/null if [$?-eq 0] Then echo "$ip" fi} & let iTunes + done wait echo "all finish." 1234567891011121314153.6 three loop implementation values are added every time #! / bin/bash-for implementation-for i in {1... 100} do let Sum=$sum+$i done echo "sum=$sum"-while implementation-iTune1 while [$I-le 100] do let sum=$sum+$i let iTunes + done echo "sum:$sum"-- until implementation-iTunes 1 until [$I-gt 100] Do let sum+=$i let iTunes + done echo "sum:$sum" the above is what the while until of the BASH loop refers to Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.