proper way to detect shell exit code when errexit option set

后端 未结 14 1545
甜味超标
甜味超标 2021-01-30 12:52

I prefer to write solid shell code, so the errexit & nounset is alway set.

The following code will stop at bad_command line

#!/bin/b         


        
14条回答
  •  旧巷少年郎
    2021-01-30 13:28

    In bash you can use the trap builtin which is quite nice. See https://unix.stackexchange.com/questions/79648/how-to-trigger-error-using-trap-command

    Not sure how portable it is with other shells.. so YMMV

提交回复
热议问题