0

したがって、次のようなbashスクリプトがあります。

Command1 -- If error occurs, ignore error and continue execution
Command2 -- If error occurs, ignore error and continue execution
Command3 -- If error occurs, stop execution, exit the script with the error
Command4 -- If error occurs, stop execution, exit the script with the error
Command5 -- If error occurs, stop execution, exit the script with the error
Command6 -- If error occurs, ignore error and continue execution

特定のコマンドをチェックして、エラーが発生したかどうかを確認する必要があります。エラーが発生した場合は、エラー コード (Comand3、4、5) でスクリプトを終了します。ただし、特定のコマンド (Command1,2,6) も意図的に無視したいので、「set -e」は使用できません。

関数内でコマンド 3、4、および 5 を組み合わせて、これらのコマンドのいずれかがエラーをスローした場合にスクリプトが終了するように実行する方法はありますか? また、スクリプトが終了する前に何らかのクリーンアップを実行したい場合 (例外が発生した場合にコードが実行される Java の catch 句に似ています)、どうすれば実行できますか?

ありがとう

4

1 に答える 1