shell script - to determine whether the previous command executed successfully

Reference https://www.cnblogs.com/lwmp/p/6292350.html

if [ $? -ne 0 ]; then
    echo "fail"
else
    echo "success"
fi

or

if [ $? -eq 0 ]; then
    echo "success"
else
    echo "fail"
fi

shell:

-eq  等于

-ne  不等于

-gt  大于

-lt  小于

ge  大于等于

le  小于等于

Reproduced in: https: //www.jianshu.com/p/e87ab4e0b182

Guess you like

Origin blog.csdn.net/weixin_33736048/article/details/91096148