How to check the exit status using an if statement

后端 未结 7 1662
北荒
北荒 2020-11-29 16:27

I was wondering what would be the best way to check the exit status in an if statement in order to echo a specific output.

I\'m thinking of it being

         


        
7条回答
  •  清歌不尽
    2020-11-29 16:44

    $? is a parameter like any other. You can save its value to use before ultimately calling exit.

    exit_status=$?
    if [ $exit_status -eq 1 ]; then
        echo "blah blah blah"
    fi
    exit $exit_status
    

提交回复
热议问题