Bashでset -x
とするとデバッグモードとして処理内容が逐次出力されますが、PS4
という環境変数で出力内容を調整できます。
test.sh
#!/usr/bin/env bash PS4='+ [${BASH_SOURCE}:${LINENO}] ${FUNCNAME:+$FUNCNAME(): }' set -x hello() { name=$1 echo "Hello $name" } hello 'World'
これを実行すると、以下のようにソース名(BASH_SOURCE
)と行数(LINENO
)、関数の場合は関数名(FUNCNAME
)が出力されます。
% bash test.sh + [test.sh:11] hello World + [test.sh:7] hello(): name=World + [test.sh:8] hello(): echo 'Hello World'