Writing try catch finally in shell

后端 未结 6 1156
说谎
说谎 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:52

    Well, sort of:

    { # your 'try' block
        executeCommandWhichCanFail &&
        mv output
    } || { # your 'catch' block
        mv log
    }
    
     rm tmp # finally: this will always happen
    

提交回复
热议问题