使用seq产生
1
2
3
for
i
in
`
seq
1 100`;
do
echo
$i
done
使用条件循环
1
2
3
for
((i=1;i<100;i++));
do
echo
$i
done
使用while循环
1
2
3
4
5
i=1
while
(($i<100));
do
echo
$i
i=`
expr
$i + 1`
done
i=`expr $i + 1`还可以改为i=$(($i+1))加快运算速度(看shell支持与否)
最慢的方法
1
2
3
for
i
in
{1..100};
do
echo
$i
done
实例 批量添加路由表:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
#print the route rulers for cczu
#to make this take effect ,pass it to shell with a pipe
#eg: route-cczu.sh |sh
#via:ihipop@gmail.com
igw=219.230.149.1
for
ip
in
{144..159};
do
echo
route add -net 219.230.$ip.0 netmask 255.255.255.0 gw $igw dev eth0
done
for
ip
in
{65..70};
do
echo
route add -net 211.65.$ip.0 netmask 255.255.255.0 gw $igw dev eth0
done
for
ip
in
`
seq
1 65`;
do
echo
route add -host 211.65.64.$ip gw $igw dev eth0
done
for
((ip=16;ip<=20;ip++));
do
echo
route add -net 172.$ip.0.0 netmask 255.255.0.0 gw $igw dev eth0
done
chmod +x route-cczu.sh
./route-cczu.sh |sh
--本篇文章转自:在linux shell中使用for遍历产生的递增数字序列的N种方法
转载请注明原文地址: https://ju.6miu.com/read-1000412.html