8
7

More than 5 years have passed since last update.

bash > スクリプトの実行内容を表示しながら実行する > bash -x

Last updated at Posted at 2015-01-09

以下のようなスクリプトがtest.shという名前であるとする。

#!/bin/env bash
touch afile
cp afile bfile

bash test.shを実行した時は処理内容が何も表示されない。

bash -x test.shとすると、以下のように処理内容が表示されるようになる。

+ touch afile
+ cp afile bfile



-xオプションはデバッグモードにするオプションとのこと。以下のようなスクリプトがあった時に、どこで終了したかわかりデバッグに役立つ。
#!/bin/env bash
inp=1
if [ $inp -eq 2 ] ; then
  exit
fi 
if [ $inp -eq 1 ] ; then
  exit
fi 
echo "TEST"

上記の実行結果は以下の通りとなり、-eq 1のif文で終了しているのがわかる。

+ inp=1
+ '[' 1 -eq 2 ']'
+ '[' 1 -eq 1 ']'
+ exit
8
7
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
8
7