Add (collect) exit codes in bash

前端 未结 7 911
执念已碎
执念已碎 2021-02-08 02:28

I need to depend on few separate executions in a script and don\'t want to bundle them all in an ugly \'if\' statement. I would like to take the exit code \'$?\' of each executi

相关标签:
7条回答
  • 2021-02-08 03:11

    Use the $(( ... )) construct.

    $ cat st.sh
    RESULT=0
    true
    RESULT=$(($RESULT + $?))
    false
    RESULT=$(($RESULT + $?))
    false
    RESULT=$(($RESULT + $?))
    echo $RESULT
    $ sh st.sh
    2
    $
    
    0 讨论(0)
提交回复
热议问题