How to check the exit status using an if statement

后端 未结 7 1668
北荒
北荒 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:54

    Alternative to explicit if statement

    Minimally:

    test $? -eq 0 || echo "something bad happened"

    Complete:

    EXITCODE=$?
    test $EXITCODE -eq 0 && echo "something good happened" || echo "something bad happened"; 
    exit $EXITCODE
    

提交回复
热议问题