在linux shell中使用for遍历产生的递增数字序列的N种方法
来源:互联网 发布:反arp攻击软件 编辑:程序博客网 时间:2024/06/07 07:56
使用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种方法
0 0
- 在linux shell中使用for遍历产生的递增数字序列的N种方法
- 在linux shell中使用for遍历产生的递增数字序列的N种方法
- 在DataGrid中产生一个递增的数字列
- Shell排序的递增序列
- linux shell 中数组的定义和for循环遍历
- 给定n*n的数字矩阵,每行从左到右是严格递增, 每列也是严格递增,判断k是否在这个矩阵中
- linux:使用seq命令产生数字序列
- shell中产生随机数的方法
- Linux产生序列数字
- hdu1027在1-N自然数组成递增序列,找第M小的序列!难
- 在有序递增数组中查找一个缺少的数字
- Oracle 产生序列的 6 种方法
- struts2 遍历Map的N中方法
- 有多少种方式可以在vim中插入递增的数字
- 论C++11 中vector的N种遍历方法
- 论C++11 中vector的N种遍历方法
- 论C++11 中vector的N种遍历方法
- 数字序列随机产生的算法
- Vue组件学习
- DirectX修复windows下.exe文件启动失败。
- Android实训案例(三)——实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果!
- runspec 的选项说明(spec2006官方文档的翻译)
- Android 渗透测试学习手册 ARM 利用
- 在linux shell中使用for遍历产生的递增数字序列的N种方法
- linux编程之socket
- 第十四周--折半查找
- 根据url地址,下载图片【IO流】
- 第十四周项目3--是否有二叉排序树?
- 带变量的string资源定义
- EventBus
- 集算器实现将两张一对多的表生成一个宽表
- Jmeter之五:监听器(一)