在bash脚本,我怎么能当某个条件时退出整个脚本? [英] In a bash script, how can I exit the entire script if a certain condition occurs?

查看:126
本文介绍了在bash脚本,我怎么能当某个条件时退出整个脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Bash中编写脚本来测试一些code。然而,似乎傻如果编译code放在首位无法运行测试,在这种情况下,我就放弃测试。

I'm writing a script in Bash to test some code. However, it seems silly to run the tests if compiling the code fails in the first place, in which case I'll just abort the tests.

有没有办法,我可以做到这一点没有包装while循环内的整个脚本,并使用休息?有点像讨债顿顿转到?

Is there a way I can do this without wrapping the entire script inside of a while loop and using breaks? Something like a dun dun dun goto?

推荐答案

试试这个语句:

exit 1

替换 1 与相应的错误codeS。另请参见退出codeS带有特殊含义

Replace 1 with appropriate error codes. See also Exit Codes With Special Meanings.

这篇关于在bash脚本,我怎么能当某个条件时退出整个脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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