最终在shell中编写try catch [英] Writing try catch finally in shell
本文介绍了最终在shell中编写try catch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有像Java try catch一样的linux bash命令? 还是linux shell总是会继续运行?
Is there a linux bash command like the java try catch finally? Or does the linux shell always go on?
try {
`executeCommandWhichCanFail`
mv output
} catch {
mv log
} finally {
rm tmp
}
推荐答案
好吧,
{ # your 'try' block
executeCommandWhichCanFail &&
mv output
} || { # your 'catch' block
mv log
}
rm tmp # finally: this will always happen
这篇关于最终在shell中编写try catch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文