proper way to detect shell exit code when errexit option set

后端 未结 14 1841
甜味超标
甜味超标 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:48

    Agree with comments, so if you can give up errexit then you can easily shorten your code to

     bad_command || do_err_handle
     good_command
    

    I hope this helps.

提交回复
热议问题