shellのモジュールでエラーが発生した時、 trap して LINENO 変数とか参照すると、モジュールでの行数とか出てきて分かりづらい。
なんかいい手は無いのかな?実行中のファイルを参照できる変数とかないのか?($0だと親シェルのファイル名が出る)
test.sm
trap 'echo "Error at line ${LINENO}. Command: ${BASH_COMMAND}. Exit code: $?"; exit 1' ERR command() { error # this is line 4. }
test.sh
#!/bin/sh source ./test.sm command # this is line 6
実行結果
sh test.sh ./test.sm: line 4: error: コマンドが見つかりません Error at line 4. Command: error. Exit code: 127