20
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

シェルスクリプト set -eux

Last updated at Posted at 2021-03-22

set -eux

dockerhubのshファイルを読んでいた際にset -euxというコマンドに何度も出くわしました。
調べると便利なオプションだったのでメモとして残しておきます。

シェルスクリプトの上部にset -eux記述しておくことで、その後のシェルの動作に対して、オプション的な効果を付与することができます。

オプション | 意味

  • | -
    -e | 何かのエラーが発生した時点で、処理を中断
    -u | 未定義の変数を使ったらエラー
    -x | 実行したコマンドを標準エラーに出力

もっとこだわりたいあなたへ

-o pipefailというオプションを最近みました。

#!/bin/bash
set -euxo pipefail

パイプの途中でエラーがあった場合、そのコードの終了ステータスを引き継ぐというオプションです。
こちらもデフォルトで使用していいですね。

参考

set man page

初心者向け、「上手い」シェルスクリプトの書き方メモ - Qiita

20
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?