File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -261,11 +261,11 @@ script.sh:行4: foo: 未找到命令
261
261
262
262
## set -E
263
263
264
- 设置 ` -e ` 参数,会导致 ` trap ` 命令失效 (参考《trap 命令》一章), ` -E ` 参数可以纠正这个行为。
264
+ 一旦设置了 ` -e ` 参数,会导致函数内的错误不会被 ` trap ` 命令捕获 (参考《trap 命令》一章)。 ` -E ` 参数可以纠正这个行为,使得函数也能继承 ` trap ` 命令 。
265
265
266
266
``` bash
267
267
#! /bin/bash
268
- set -euo pipefail
268
+ set -e
269
269
270
270
trap " echo ERR trap fired!" ERR
271
271
@@ -278,14 +278,14 @@ myfunc()
278
278
myfunc
279
279
```
280
280
281
- 上面的脚本 ,` myfunc ` 函数调用了一个不存在的命令 ` foo ` ,导致执行这个函数会报错。
281
+ 上面示例中 ,` myfunc ` 函数内部调用了一个不存在的命令 ` foo ` ,导致执行这个函数会报错。
282
282
283
283
``` bash
284
284
$ bash test.sh
285
285
test.sh:行9: foo:未找到命令
286
286
```
287
287
288
- 但是,由于设置了` set -e ` ,脚本报错后并没有被 ` trap ` 命令捕获,需要加上` -E ` 参数才可以。
288
+ 但是,由于设置了` set -e ` ,函数内部的报错并没有被 ` trap ` 命令捕获,需要加上` -E ` 参数才可以。
289
289
290
290
``` bash
291
291
#! /bin/bash
You can’t perform that action at this time.
0 commit comments