我想在Bash脚本中引发一个错误消息测试用例失败!!!。如何在Bash中这样做?
I want to raise an error in a Bash script with message "Test cases Failed !!!". How to do this in Bash ?
例如:
if [ condition ]; then raise error "Test cases failed !!!" fi推荐答案
这取决于你想要的地方将存储错误消息。
This depends on where you want the error message be stored.
您可以执行以下操作:
echo "Error!" > logfile.log exit 125或以下:
echo "Error!" 1>&2 exit 64当您引发异常时,停止程序的执行。
When you raise an exception you stop the program's execution.
您还可以使用 exit xxx 其中 xxx 是您可能要返回到操作系统的错误代码(从0到255)。这里 125 和 64 只是您可以退出的随机代码。当您需要向操作系统指出程序异常停止(例如发生错误)时,需要将非零退出代码传递到 exit 。
You can also use something like exit xxx where xxx is the error code you may want to return to the operating system (from 0 to 255). Here 125 and 64 are just random codes you can exit with. When you need to indicate to the OS that the program stopped abnormally (eg. an error occurred), you need to pass a non-zero exit code to exit.
作为@chepner 指出,您可以执行 exit 1 ,这将意味着未指定的错误。
As @chepner pointed out, you can do exit 1, which will mean an unspecified error.
更多推荐
提高bash脚本中的错误
发布评论