0
2

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 3 years have passed since last update.

bashの先頭に書くやつ

Last updated at Posted at 2021-01-20

シェルスクリプトの一行目に書く #から始まるコードのことをshebang(シェバン)という。

シェバン

絶対パスで指定。このパスにbashが無ければエラーになる。

# !/bin/bash

envで指定。このパスにbashが無ければエラーになる。$PATH上のbashを探す。
この書き方のほうがエラーになる率が低いので、こちらで書く。

# !/usr/bin/env bash

オプション

エラーが出たら終了してくれる。

-e

デバッグ情報を出力してくれる

-x

結論

バッシュのスクリプトの先頭には、こう書いておく。

# !/usr/bin/env bash
set -ex

参考

https://moneyforward.com/engineers_blog/2015/05/21/bash-script-tips/
https://qiita.com/d_shimizu/items/c01f29f8398cc7f5c396

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?