Skip to content

Commit dc9098d

Browse files
committed
docs: edit function
1 parent 0bcc2d3 commit dc9098d

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

docs/function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function fn() {
2626

2727
```bash
2828
hello() {
29-
echo "Hello $1";
29+
echo "Hello $1"
3030
}
3131
```
3232

@@ -126,7 +126,7 @@ $ log_msg "This is sample log message"
126126
[ 2018-08-16 19:56:34 ]: This is sample log message
127127
```
128128

129-
## 返回值
129+
## return 命令
130130

131131
`return`命令用于从函数返回一个值。函数执行到这条命令,就不再往下执行了,直接返回了。
132132

docs/startup.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ $ source .bashrc
119119
`source`命令最大的特点是在当前 Shell 执行脚本,不像直接执行脚本时,会新建一个子 Shell。所以,`source`命令执行脚本时,不需要`export`变量。
120120

121121
```bash
122+
#!/bin/bash
122123
# test.sh
123124
echo $foo
124125
```
@@ -145,3 +146,15 @@ $ bash test.sh
145146
$ . .bashrc
146147
```
147148

149+
`source`命令的另一个用途,是在脚本内部加载外部库。
150+
151+
```bash
152+
#!/bin/bash
153+
154+
source ./lib.sh
155+
156+
function_from_lib
157+
```
158+
159+
上面脚本在内部使用`source`命令加载了一个外部库,然后就可以在脚本里面,使用这个外部库定义的函数。
160+

0 commit comments

Comments
 (0)