Skip to content

Commit c84122d

Browse files
ZhuangZhu-74jaywcjlove
authored andcommitted
Update builtin and help (jaywcjlove#119)
* Update builtin.md 修改并丰富了文档,将一小部分之前属于help的内容修改后放到了这里。 * Update help.md 配合builtin命令的更改进行内容调整 * Update builtin.md 增加内建命令帮助信息提示
1 parent a5f68bc commit c84122d

2 files changed

Lines changed: 43 additions & 23 deletions

File tree

‎command/builtin.md‎

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,61 @@
11
builtin
22
===
33

4-
执行shell内部命令
4+
执行bash内建命令。
55

66
## 补充说明
77

8-
**builtin命令** 用于执行指定的shell内部命令,并返回内部命令的返回值。builtin命令在使用时,将不能够再使用Linux中的外部命令。当系统中定义了与shell内部命令相同的函数时,使用builtin显式地执行shell内部命令,从而忽略定义的shell函数。
8+
**builtin命令** 用于执行指定的bash内建命令,并返回内部命令的返回值。builtin命令在使用时,Linux中同名的外部命令及同名的shell函数失效。
99

1010
### 语法
1111

1212
```shell
13-
builtin(参数)
13+
builtin(bash内建命令)(参数)
1414
```
1515

1616
### 参数
1717

18-
shell内部命令:指定需要执行的shell内部命令。
18+
bash内建命令:指定需要执行的bash内建命令。
19+
20+
(可选)参数:传递给bash内建命令的参数。
21+
22+
### 提示
23+
24+
**同名情况下的优先级顺序**
25+
26+
builtin 内建命令 > 函数 > 内建命令 > 外部命令
27+
28+
```shell
29+
#!/bin/bash
30+
#此时内建命令优先使用
31+
echo "the Great Wall"
32+
#调用内建命令type,显示命令的类型
33+
type -t echo
34+
#定义 echo 函数
35+
echo(){
36+
printf "123\n"
37+
}
38+
#此时同名函数优先使用
39+
echo
40+
type -t echo
41+
#此时内建命令优先使用
42+
builtin echo -e "backslash \\"
43+
```
44+
45+
```shell
46+
#输出结果
47+
the Great Wall
48+
builtin
49+
123
50+
function
51+
backslash \
52+
```
53+
54+
内建命令的帮助信息请参考 'help' 命令
1955

2056
### 实例
2157

22-
使用builtin命令执行shell内部命alias显示命令别名,输入如下命令:
58+
使用builtin命令执行bash内建命令alias:
2359

2460
```shell
2561
builtin alias # 执行shell内部指令
@@ -35,4 +71,4 @@ alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-ti
3571
上面的命令执行后,将输出当前系统下的命令别名。
3672

3773

38-
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
74+
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->

‎command/help.md‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,7 @@ A:因为除了bash内建的echo,GNU/linux的coreutils包里也有该命令
4242

4343
PS:当你在shell脚本里定义了一个叫 'echo' 的函数,那么调用的时候优先级会如何呢?
4444

45-
```shell
46-
#!/bin/bash
47-
#type也是内建命令
48-
type -t echo
49-
echo(){
50-
printf "123\n"
51-
}
52-
type -t echo
53-
```
54-
55-
```shell
56-
#输出结果
57-
builtin
58-
function
59-
```
60-
61-
函数优先于内建命令,内建命令优先于外部命令。
45+
请参考 'builtin' 命令
6246

6347
Q:我需要获得更多的bash的相关帮助信息
6448

0 commit comments

Comments
 (0)