Skip to content

Commit 24d676b

Browse files
authored
Merge pull request jaywcjlove#127 from ZhuangZhu-74/master
create files for bash builtin
2 parents 33d9db4 + 99ed928 commit 24d676b

4 files changed

Lines changed: 198 additions & 0 deletions

File tree

command/break.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
break
2+
===
3+
4+
结束for,while或until循环。
5+
6+
## 概要
7+
8+
```shell
9+
break [n]
10+
```
11+
12+
## 主要用途
13+
14+
- 结束for,while或until循环,可指定退出几层循环。
15+
16+
17+
## 参数
18+
19+
n(可选):大于等于1的整数,用于指定退出几层循环。
20+
21+
## 返回值
22+
23+
返回成功除非n小于1。
24+
25+
## 例子
26+
27+
```shell
28+
# break的可选参数n缺省值为1。
29+
# 从外层for循环继续执行。
30+
for((i=3;i>0;i--)); do
31+
for((j=3;j>0;j--)); do
32+
if((j==2)); then
33+
# 换成break 1时结果一样
34+
break
35+
fi
36+
printf "%s %s\n" ${i} ${j}
37+
done
38+
done
39+
# 输出结果
40+
3 3
41+
2 3
42+
1 3
43+
```
44+
45+
```shell
46+
# 当n为2时:
47+
# 退出两层循环,结束。
48+
for((i=3;i>0;i--)); do
49+
for((j=3;j>0;j--)); do
50+
if((j==2)); then
51+
break 2
52+
fi
53+
printf "%s %s\n" ${i} ${j}
54+
done
55+
done
56+
# 输出结果
57+
3 3
58+
```
59+
60+
### 注意
61+
62+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
63+
64+
65+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

command/continue.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
continue
2+
===
3+
4+
结束本次循环,继续执行下一个for,while或until循环。
5+
6+
## 概要
7+
8+
```shell
9+
continue [n]
10+
```
11+
12+
## 主要用途
13+
14+
- 结束本次循环,继续执行下一个for,while或until循环;可指定从第几层循环继续执行。
15+
16+
17+
## 参数
18+
19+
n(可选):大于等于1的整数,用于指定从第几层循环继续执行。
20+
21+
## 返回值
22+
23+
返回状态为成功除非n小于1。
24+
25+
## 例子
26+
27+
```shell
28+
# continue的可选参数n缺省值为1。
29+
for((i=3;i>0;i--)); do
30+
# 跳到内层for循环继续执行。
31+
for((j=3;j>0;j--)); do
32+
if((j==2)); then
33+
# 换成continue 1时结果一样
34+
continue
35+
fi
36+
printf "%s %s\n" ${i} ${j}
37+
done
38+
done
39+
# 输出结果
40+
3 3
41+
3 1
42+
2 3
43+
2 1
44+
1 3
45+
1 1
46+
```
47+
48+
```shell
49+
# 当n为2时:
50+
# 跳到外层for循环继续执行。
51+
for((i=3;i>0;i--)); do
52+
for((j=3;j>0;j--)); do
53+
if((j==2)); then
54+
continue 2
55+
fi
56+
printf "%s %s\n" ${i} ${j}
57+
done
58+
done
59+
# 输出结果
60+
3 3
61+
2 3
62+
1 3
63+
```
64+
65+
### 注意
66+
67+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
68+
69+
70+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

command/false.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
false
2+
===
3+
4+
返回状态为失败。
5+
6+
## 概要
7+
8+
```shell
9+
false
10+
```
11+
12+
## 主要用途
13+
14+
- 用于和其他命令进行逻辑运算。
15+
16+
## 返回值
17+
18+
返回状态总是失败;返回值为1。
19+
20+
21+
### 注意
22+
23+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
24+
25+
26+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

command/true.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
true
2+
===
3+
4+
返回状态为成功。
5+
6+
## 概要
7+
8+
```shell
9+
true
10+
```
11+
12+
## 主要用途
13+
14+
- 用于和其他命令进行逻辑运算。
15+
16+
## 返回值
17+
18+
返回状态总是成功;返回值为0。
19+
20+
## 例子
21+
22+
```shell
23+
# 当你的脚本设置set -e时,任何返回值为失败的命令都会使得脚本退出。
24+
set -e
25+
# 如何临时跳过呢?下面的语句使用逻辑或操作符连接true,返回值一定为真。
26+
some_command || true
27+
28+
# 当然,和python的pass一样,也可以用作条件语句临时占位。
29+
```
30+
31+
32+
### 注意
33+
34+
1. 该命令是bash内建命令,相关的帮助信息请查看`help`命令。
35+
36+
37+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

0 commit comments

Comments
 (0)