检查"make"命令的输出.并在失败时退出bash脚本 [英] Check the output of "make" and exit bash script if it fails

查看:118
本文介绍了检查"make"命令的输出.并在失败时退出bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但是,我不只是bash的小玩意儿;我已经编写了一个bash脚本,它将执行我的cmake,make和C ++可执行文件.

I'm a nube to more than just bash, however; I've written a bash script that will execute my cmake, make, and c++ executable.

#! /bin/bash
cmake .
make
./pcl_visualizer_demo   <-- This is my executable

这很好用,除非当我的代码无法编译时,它将执行旧的可执行文件并使我一团糟.我希望将make的输出放入if语句中,该语句仅在make成功时才运行可执行文件.我在stackoverflow上的其他文章中尝试了很多bash事情.有些问题似乎是make的输出不是字符串,例如:

This works great except when my code fails to compile it executes the old executable and leaves me with a mess. I was hoping to put the output of make into an if statement that only runs the executable when make is successful. I've tried a great many bash things from other posts here on stackoverflow. Some of the problems seem to be that the output of make is not a string for example:

OUTPUT = make
echo $OUTPUT

给予:

[100%] Built target pcl_visualizer_demo

但无法使用:

if [`expr match "$OUTPUT" '[100%] -eq 5]; then ./pcl_visulizer_demo; fi

更不用说我认为这行可能有不止一件事.我也尝试过:

Not to mention I think there may be more than one thing wrong with this line. I also tried:

if [diff <(echo "$OUTPUT") <(echo '[100%] Built target pcl_visualizer_demo' -n]; then ./pcl_visulizer_demo; fi

再次可能是我没有正确执行它.任何帮助

Again it could be that I'm not implementing it right. Any help

推荐答案

只需检查make的退出代码:

Just check the exit code of make:

cmake . || exit 1
make || exit 1
./pcl_visualizer_demo 

这篇关于检查"make"命令的输出.并在失败时退出bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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