In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article is about using while loops in bash shell scripts. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.
Like the for loop, the while loop is a loop that starts with a constraint. This means that the condition needs to be checked before executing the while loop. In most cases, it also does all the work that a for loop can do, but it has its own programming advantages.
Grammar:
while [ condition ]do//execute done
Example of while loop in bash
For example, when the value of i is greater than 10, the following loop is executed 10 times and exits.
#!/ bin/bashi=1while [$i-le10]do echo "This is looping number $i" leti++done
while infinite loop in bash
An infinite for loop is an endless loop. The loop continues until it is forced to stop using ctrl+c.
#!/ bin/bashwhiletruedo echo "Press CTRL+C to Exit"done
But we can also use conditional statements like if to terminate the loop when certain conditions are matched.
#!/ bin/bashwhiletruedo if [ condition ];do exit fidone
In bash scripts, we can also write while loops similar to C.
#!/ bin/bashi=1while((i
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.