What does set -e mean in a bash script?

后端 未结 8 954
醉酒成梦
醉酒成梦 2020-11-22 15:46

I\'m studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file.

The scr

8条回答
  •  攒了一身酷
    2020-11-22 16:21

    I found this post while trying to figure out what the exit status was for a script that was aborted due to a set -e. The answer didn't appear obvious to me; hence this answer. Basically, set -e aborts the execution of a command (e.g. a shell script) and returns the exit status code of the command that failed (i.e. the inner script, not the outer script).

    For example, suppose I have the shell script outer-test.sh:

    #!/bin/sh
    set -e
    ./inner-test.sh
    exit 62;
    

    The code for inner-test.sh is:

    #!/bin/sh
    exit 26;
    

    When I run outer-script.sh from the command line, my outer script terminates with the exit code of the inner script:

    $ ./outer-test.sh
    $ echo $?
    26
    

提交回复
热议问题