bash – shell脚本中的异常处理?

我在shell脚本中寻找异常处理机制。有没有任何try,catch等效机制在shell脚本?
在bash中没有真正的try / catch(我假设你使用bash),但是你可以使用&&&或||。

在此示例中,如果a_command失败(返回非零值),则要运行fallback_command:

a_command || fallback_command

在此示例中,如果a_command成功(返回0),则要执行second_command:

a_command && second_command

它们可以通过使用subshel​​l容易地混合在一起,例如,以下命令将执行a_command,如果成功,它将运行other_command,但是如果a_command或other_command失败,fallback_command将被执行:

(a_command && other_command) || fallback_command

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...