错误退出脚本 [英] Exit a Script On Error

查看:142
本文介绍了错误退出脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建具有这样的if功能的Shell脚本:

I'm building a Shell Script that has a if function like this one:

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

...

我希望在显示错误消息后完成脚本的执行.我该怎么办?

I want the execution of the script to finish after displaying the error message. How I can do this?

推荐答案

您是否正在寻找 exit ?

Are you looking for exit?

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

This is the best bash guide around. 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

...

这篇关于错误退出脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆