Skip to content

set章节-E参数说明 #51

@zybeasy

Description

@zybeasy

set章节

设置-e参数,会导致trap命令失效(参考《trap 命令》一章),-E参数可以纠正这个行为。

对于-E参数的解释不同于官方手册

-E If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR trap is normally not in‐herited in such cases.
例如,函数中的错误是不会触发err trap,设置-E以后,函数中的错误也可以触发err trap

示例中的err trap是因为myfunc的调用返回值非0,所以触发err trap,如果在myfunc中添加return 0,就不会有err trap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions