While loop
1)
While CONDITION; Do
Statement
Statement
< change the loop condition true and false statement >
Done
Write a script that calculates 1---100 of the AND
#!/bin/bash
#
Sum=0
I=1
While [$i-le 100]; Do
Let sum= $sum + $i
Let i= $i +1
Done
Echo $sum
2)
While true; Do
Statement
Statement
Done
#!/bin/bash
#
While true; Do
Read-p "Please enter your choice:" Choice
if [$choice = = "Q"]; Then
Break
Fi
Done
#!/bin/bash
#
While true; Do
Uptime
Sleep 3
Done
3)
while read line; Do
Statement
Statement
Done < file
#!/bin/bash
#
Bash_num=0
Nologin_num=0
while read line; Do
sh_name=$ (echo $line | awk-f: ' {print $7} ')
Case $sh _name in
/bin/bash)
Let bash_num= $bash _num+1
;;
/sbin/nologin)
Let nologin_num= $nologin _num+1
;;
Esac
Done </etc/passwd
Echo $bash _num
Echo $nologin _num
Util cycle:
Util CONDITION; Do
Statement
Statement
Done
When the condition is false, the loop is executed and the condition is true, ending the loop
This article is from the "lyw666" blog, make sure to keep this source http://lyw666.blog.51cto.com/12823216/1957415
The while loop of the shell loop structure