一文读懂Shell脚本中循环语句for,while,until用法
来源:互联网 发布:往届生银行知乎 编辑:程序博客网 时间:2024/05/21 17:52
1
2
3
4
for
变量
in
串行
do
执行命令
done
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
for
k
in
$(
seq
1 10 )
do
mkdir
/home/kuangl/aaa
${k}
cd
/home/kuangl/aaa
${k}
for
l
in
$(
seq
1 10 )
do
mkdir
bbb${l}
cd
/home/kuangl/aaa
${k}
done
cd
..
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@test01 kuangl]
# ll
total 80
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa1
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa10
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa2
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa3
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa4
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa5
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa6
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa7
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa8
drwxr-xr-x 12 root root 4096 Jul 20 01:23 aaa9
[root@test01 kuangl]
# cd aaa1
[root@test01 aaa1]
# ll
total 40
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb1
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb10
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb2
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb3
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb4
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb5
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb6
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb7
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb8
drwxr-xr-x 2 root root 4096 Jul 20 01:23 bbb9
1
1
2
3
4
5
6
7
#!/bin/bash
DIR=
"/var"
cd
$DIR
for
k
in
$(
ls
$DIR)
do
[ -d $k ] &&
du
-sh $k
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@test01 scripts]
# ./var.sh
276M cache
4.0K cvs
84K db
8.0K empty
4.0K
ftp
4.0K games
4.0K gdm
21G lib
4.0K
local
16K lock
7.4G log
4.0K logs
0 mail
4.0K nis
4.0K opt
4.0K preserve
336K run
3.7G spool
212K tmp
4.1G www
4.0K yp
1
2
3
4
while
条件测试
do
执行命令
done
1
2
3
4
5
#!/bin/bash
while
read
kuangl
do
echo
${kuangl}
done
<
/home/kuangl/scripts/testfile
1
2
3
[root@test01 scripts]
# ./while_test01.sh
aaaaaaa
bbbbbbb
1
2
3
4
5
6
7
8
9
#!/bin/bash
declare
-i i=1
declare
-i
sum
=0
while
((i<=10))
do
let
sum
+=i
let
++i
done
echo
$
sum
1
2
[root@test01 scripts]
# ./while_02.sh
55
1
1
2
3
4
until
条件测试
do
执行命令
done
1
2
3
4
5
6
7
8
9
#!/bin/bash
declare
-i i=10
declare
-i
sum
=0
until
((i>10))
do
let
sum
+=i
let
++i
done
echo
$
sum
1
2
[root@test01 scripts]
# ./until_test01.sh
10
阅读全文
0 0
- 一文读懂Shell脚本中循环语句for,while,until用法
- Shell脚本中循环语句for,while,until用法
- shell 脚本之for while until循环
- Shell中的循环语句for、while、until
- shell中for、while、until循环
- Shell脚本的基本语法(一) if判断、for循环、while循环和until循环
- Shell 脚本之循环语句(for,while,until)以及case,select,break,continue实例详解
- shell 循环 for while until ....
- shell循环,for 、while、until
- shell(for、while、until)循环
- 循环语句 for while until
- Shell脚本基础学习(七)----for while until循环
- shell脚本循环for/until/while 以及ifelse判断
- Shell中的循环语句总结(for, while, until)
- Shell中的循环语句for、while、until实例讲解
- shell for循环,while循环,until循环
- shell脚本编程中for while until三种循环的使用方法
- shell脚本编程中for while until三种循环的使用方法
- python的三种字符串格式化方法
- JS_绘图_canvas
- 整数奇偶排序
- 网络编程服务器与客户端实现代码详解
- framework watchdog源码分析
- 一文读懂Shell脚本中循环语句for,while,until用法
- python入门(十):文件的操作详解
- 八皇后问题
- 合影效果
- C语言数据结构2——双向链表的实现
- 汇编中loop格式用法分析
- 146_IO_原理_分类_标准步骤
- Opencv并行访问图像像素
- 分数线划定