What does set -e mean in a bash script?

后端 未结 8 998
醉酒成梦
醉酒成梦 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:19

    I believe the intention is for the script in question to fail fast.

    To test this yourself, simply type set -e at a bash prompt. Now, try running ls. You'll get a directory listing. Now, type lsd. That command is not recognized and will return an error code, and so your bash prompt will close (due to set -e).

    Now, to understand this in the context of a 'script', use this simple script:

    #!/bin/bash 
    # set -e
    
    lsd 
    
    ls
    

    If you run it as is, you'll get the directory listing from the ls on the last line. If you uncomment the set -e and run again, you won't see the directory listing as bash stops processing once it encounters the error from lsd.

提交回复
热议问题