proper way to detect shell exit code when errexit option set

后端 未结 14 1550
甜味超标
甜味超标 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条回答
  •  猫巷女王i
    2021-01-30 13:35

    A clean reliable way to error exit

    command_that_error_exits || { echo "Line $LINENO: Failed with Error" 1>&2; exit 1;}
    

提交回复
热议问题