3 ms·
Somewhat related to PS1 is PS4 in bash. Make your trace output more useful/verbose in your scripts: set -x export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}
by graton 5y ago
Somewhat related to PS1 is PS4 in bash.
Make your trace output more useful/verbose in your scripts:
set -x
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
This will print the filename, function name, line number, and line content during execution.
- formerly_proven 5y agoIn case someone wonders, this does retain the repeated "+" to indicate call depth: "The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection." -- this is an important feature when working on large-ish (1-10+k LoC) scripts, which end up having very deep call stacks and a flat trace output would be completely inscrutable.
- Xophmeister 5y agoIf you have 10k LoC Bash scripts, then you’ve got bigger problems!
- jethro_tell 5y agoI've run the bash 10k and all I got was this shirt!
- formerly_proven 5y agoOverall it's more like 150k LoC or something like that (split into the classic three layer architecture: "scripts", "library" and "more scripts on top"). It does work though. Much better than you'd expect from hearing "tens of thousands of lines of shell".