bash – 错误时退出脚本

前端之家收集整理的这篇文章主要介绍了bash – 错误时退出脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在构建一个Shell脚本,它有一个if函数,像这样:
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

...

我希望脚本的执行显示错误消息后完成。我怎么能这样做?@H_403_4@

您是在找 exit

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

在上下文中:@H_403_4@

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

...
原文链接:https://www.f2er.com/bash/391664.html

猜你在找的Bash相关文章