检测在bash脚本中找不到的命令 [英] detecting command not found in bash script

查看:142
本文介绍了检测在bash脚本中找不到的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列要执行的命令.但是,无论何时发生找不到命令"错误,我都需要退出.因此,执行输出后检查不是一个选择

I have a series of command to execute. However I need to exit whenever 'command is not found' error occurs. So post execution check of output is not an option

"$?"当找不到命令"并成功执行时,变量等于零.

The "$?" variable is equal zero when 'command is not found' and on success.

推荐答案

如果应该通过脚本完成此操作,则很自然地可以使用条件语句来表达这种行为:

If this should be done from a script, it's natural to use a conditional to express this kind of behaviour:

asdf 2> /dev/null || exit 1

这篇关于检测在bash脚本中找不到的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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