Uma maneira fácil de melhorar a saída de rastreamento é o seguinte fragmento de código:
PS4='[${BASH_SOURCE[0]:-inherited}:${LINENO}:${FUNCNAME[0]:-main}] '
set -o xtrace
Isso mostrará a você:
- arquivo de origem
- número da linha de origem
- nome da função
veja também página wiki para c42-common-functions
Exemplo de saída:
$ c42_loglevel_trace
$ pidkill --help
++ '[' '+ ' == '+ ' ']'
++ PS4='[${BASH_SOURCE[0]:-inherited}:${LINENO}:${FUNCNAME[0]:-main}] '
...
[/usr/local/bin/pidkill:224:main] '[' 1 -eq 0 ']'
[/usr/local/bin/pidkill:230:main] signal=KILL
[/usr/local/bin/pidkill:231:main] '[' 1 -gt 0 ']'
[/usr/local/bin/pidkill:233:main] case $1 in
[/usr/local/bin/pidkill:268:main] shift 1
[/usr/local/bin/pidkill:269:main] help
[/usr/local/bin/pidkill:57:help] cat
pidkill <-h|--help> this help
[/usr/local/bin/pidkill:70:help] copyLeft
[/usr/local/bin/pidkill:13:copyLeft] echo ''
...
Uma alternativa é bashdb :
This is a complete rewrite of the Korn Shell debugger from Bill Rosenblatt's 'Learning the Korn Shell', published by O'Reilly and Associates (ISBN 1-56592-054-6) with changes by Michael Loukides and Cigy Cyriac. However, this code now depends on a number of debugging support features that are neither part of the POSIX standard nor present are in many POSIX-like shells. Although you can just use bashdb to debug scripts written in BASH, it can also be used just as a front-end for learning more about programming in BASH. As an additional aid, the debugger can be used within the context of an existing script with its functions and variables that have already been initialized; fragments of the existing code can be experimented with by changing them inside the debugger.