linux - 如果命令在 Unix shell 中失败,如何中止?

标签 linux bash shell unix gulp

我不太擅长 shell 脚本,但仍然找不到解决方案。我想运行命令 gulp tslint如果返回错误,则中止脚本。

到目前为止我尝试了gulp tslint || exit 1没有成功。我认为它以某种方式返回 true,即使当我在命令提示符下运行它时出现错误,例如

[12:30:14] Starting 'tslint'...
[12:30:14] Finished 'tslint' after 9.49 ms
[12:30:16] [gulp-tslint] error (quotemark) payment-types.ts[18, 53]: " should be '

我怎样才能让它发挥作用?

任何帮助表示赞赏。谢谢!

最佳答案

这看起来像是一个 gulp 问题,而不是一个 shell 问题。当 gulp 成功完成(即到达退出而没有引发错误)时,它不会告诉 shell 有任何问题。解决此问题的最佳方法是重新配置 gulp,将 lint 失败解释为错误。

您可以发布您的gulpfile.js吗?特别是您的 tslint 任务。

可能看起来像

gulp.task('tslint', function() {
    gulp.src("**/*.ts")
        .pipe(tslint.report('prose'))
});

您可以通过将其更改为:

来指示您的记者在错误时失败:
gulp.task('tslint', function() {
    gulp.src("**/*.ts")
        .pipe(tslint.report('prose', {emitError: true}))
});

编辑:查看 gulp-tslint README有关emitError的更多详细信息

关于linux - 如果命令在 Unix shell 中失败,如何中止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30478584/

相关文章:

php - 检查远程linux服务器是否正在运行?

c - popen()/fgets() 间歇性地返回不完整的输出

linux - SSH断线后执行shell脚本最后几行

bash - 文件中行数的变量

linux - avahi-autoipd 无法获取 ipv4ll 链路本地地址

linux - 通过 bash 将参数传递给安装程序

php - 如何在 PHP 错误日志文件中获取命令行错误

python - 在 python 中运行复杂的命令行

bash - 忽略 shell 脚本中的特定错误

bash - 在 bash 脚本中使用 ffmpeg 缩放图像