Writing try catch finally in shell

后端 未结 6 1016
说谎
说谎 2021-01-30 09:52

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 {         


        
6条回答
  •  星月不相逢
    2021-01-30 10:57

    mv takes two parameters, so may be you really wanted to cat the output file's contents:

    echo `{ execCommand && cat output ; } || cat log`
    rm -f tmp
    

提交回复
热议问题