For is an important loop statement in shell programming:
Syntax 1:
For variable in list
Do
Action
.....
Done
List:
① 'Seq 1 10' #1-10
② {1 .. 10 }## 1-10
③/Etc/rc. d/rc3.d/K * # All files starting with K in the directory will be cycled once.
④ 'Pgrep-uuser1' # obtain the corresponding process loop of the user
Script:
To kill all processes of the specified user
#! /Bin/bash
#
Read-p "Please Enter the name:" user
For I in 'pgrep-u $ user'
Do
Kill-9 $ I &>/dev/null
Done
Syntax 2:
Fori = 0; I <100; I ++ ))
Do
Action
......
Done
Script implementation:
Scan hosts of the specified CIDR Block
#! /Bin/bash
#
For (I = 1; I <= 254; I ++ ))
Do
Ping-c1-w1 192.168.220. $ I &>/dev/null
If [$? -Eq 0]
Then
Echo "$ I is online ...."
Fi
Done
Running result:
650) this. width = 650; "title =" for.jpg "alt =" %720917.jpg" src = "http://www.bkjia.com/uploads/allimg/131227/22523944J-0.jpg"/>
This article is from the keepalive blog, please be sure to keep this source http://jefferyyu.blog.51cto.com/2843635/1303896