I am trying to debug a large build project which calls a bunch of bash scripts. Someone suggested modifying PS4 so I set it to the following snippet in order to print the path of the script and the line number being executed.
export PS4='\e[33m+ ${BASH_SOURCE}:${LINENO} \e[0m'
However, when BASH_SOURCE was long, I noticed that all outputs were yellow (because of \e[33m). Upon further examination, I figured out that bash was truncating PS4 whenever it was longer than about 80 chars or so and in such cases \e[0m never got executed. I googled a bit but I didn't find any documentation on this behaviour.
For now my only workaround is to truncate BASH_SOURCE manually. Is there a better way?
export PS4='\e[33m+ ${BASH_SOURCE:${#BASH_SOURCE}<80?0:-80}:${LINENO} \e[0m'
\[...\]as described in the "PROMPTING" section of the manual help? Also, there is no need to exportPS4.