shell中&& || 的执行逻辑。
1){ command1} && {command2}这种情况下,只有左边command1成功执行了,右边command2的shell才会执行。
{ # try
command1 &&
#save your output
} && { # catch
# save log for exception
}
2){command1} || {command2} 这种情况,左边command1脚本执行失败,右边command2才会执行,刚好可以实现类似try catch的功能。
{ # try
command1 &&
#save your output
} || { # catch
# save log for exception
}
stack overflow帖子:/questions/22009364/is-there-a-try-catch-command-in-bash