小编典典

出错时退出脚本

all

我正在构建一个具有以下if功能的 Shell 脚本:

if jarsigner -verbose -keystore $keyst -keystore $pass $jar_file $kalias
then
    echo $jar_file signed sucessfully
else
    echo ERROR: Failed to sign $jar_file. Please recheck the variables
fi

...

我希望在显示错误消息后完成脚本的执行。我怎么能做到这一点?


阅读 73

收藏
2022-08-27

共1个答案

小编典典

你在找exit吗?

这是最好的 bash 指南。 http://tldp.org/LDP/abs/html/

在上下文中:

if jarsigner -verbose -keystore $keyst -keystore $pass $jar_file $kalias
then
    echo $jar_file signed sucessfully
else
    echo ERROR: Failed to sign $jar_file. Please recheck the variables 1>&2
    exit 1 # terminate and indicate error
fi

...
2022-08-27