xオプションでデバッグ

こんなスクリプト test.sh があったとして、

 #!/bin/bash
 
 dir="/home/taro/tmp/"
 files=$(ls -1 $dir);
 IFS='
 '
 for f in $files; do
     echo "FILE: " $f
 done

xオプションを付けてスクリプトを実行すると、

 $ bash -x test.sh

変数の中身が確認できる。

 + dir=/home/taro/tmp/
 ++ ls -1 /home/taro/tmp/
 + files='1.txt
 2.txt
 3.txt'
 + IFS='
 '
 + for f in '$files'
 + echo 'FILE: ' 1.txt
 FILE:  1.txt
 + for f in '$files'
 + echo 'FILE: ' 2.txt
 FILE:  2.txt
 + for f in '$files'
 + echo 'FILE: ' 3.txt
 FILE:  3.txt

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2012-09-24 (月) 23:48:38