bash でシェルスクリプトを書いていて、エラー処理をif文を使って command ... if [ $? -ne 0 ] then echo ... exit 1 fi みたいに書くと、コードが見づらいのでなんとかならないかと思っていたら、 command ... || { echo ... ; exit 1 ; } こういう風に書けるのか。 Perl の「or die」みたい。ってか Perl のほうが新しいと思うけど。 command ... || echo ... ; exit 1 のように書くと exit が実行されないので要注意。って bashクックブック に書かれてました。 例 hoge1.sh #!/bin/bash mkdir log if [ $? -ne 0 ] then echo oops! exit 1 fi echo created directory. ho
![シェルスクリプトのエラー処理を見やすく書く - ablog](https://cdn-ak-scissors.b.st-hatena.com/image/square/42d17737375f5a7b4eb9fdcccdbf01e603d8b25e/height=288;version=1;width=512/https%3A%2F%2Fimages-fe.ssl-images-amazon.com%2Fimages%2FI%2F51mNJmDAzSL._SL160_.jpg)