File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ function fn() {
2626
2727``` bash
2828hello () {
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
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ $ source .bashrc
119119` source ` 命令最大的特点是在当前 Shell 执行脚本,不像直接执行脚本时,会新建一个子 Shell。所以,` source ` 命令执行脚本时,不需要` export ` 变量。
120120
121121``` bash
122+ #! /bin/bash
122123# test.sh
123124echo $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+
You can’t perform that action at this time.
0 commit comments