VOOZH about

URL: https://qiita.com/aosho235/items/4e913905a130c0eaf86d

⇱ bashスクリプトをデバッグする方法 #Bash - Qiita


👁 Image
327

Go to list of users who liked

335

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@aosho235in👁 Image
株式会社ヴァル研究所

bashスクリプトをデバッグする方法

327
Posted at

debugging - How to debug a bash script? - Unix & Linux Stack Exchangeより

bash 4.1以上にて

スクリプトの先頭に次のように書いておく

# !/bin/bash

exec 5> debug_output.txt
BASH_XTRACEFD="5"
PS4='$LINENO: '
set -x

するとdebug_output.txtにログが出力される。

exec 5>はファイルディスクリプタ5番をdebug_output.txtにするという意味。
PS4はトレース出力の際に表示されるプロンプト。$LINENOにより行番号を表示している。
set -xは実行するコマンドをトレース出力させる。

元記事にはbashdb、log4bash、Eclipse、Visual Studioo Codeを使う方法なども紹介されているが、これが一番手軽でほとんどの場合十分だと思う。

327

Go to list of users who liked

335
0

Go to list of comments

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
327

Go to list of users who liked

335