I wanted to colour red all stderr to quickly differentiate between different messages in one of my LM setup scripts. I found this one online which sort of works fine but not quite:
Code: Select all
# Colour stderr red for bash terminal
export COLOR_RED="$(tput setaf 1)"
export COLOR_RESET="$(tput sgr0)"
exec 9>&2
exec 8> >(
perl -e '$|=1; while(sysread STDIN,$a,9999) {print
"$ENV{COLOR_RED}$a$ENV{COLOR_RESET}"}'
)
function undirect(){ exec 2>&9; }
function redirect(){ exec 2>&8; }
trap "redirect;" DEBUG
PROMPT_COMMAND='undirect;'
$read "Press Enter to continue"
), and also the most important it prevents me to run $sudo su
as terminal would simply hang. I have to literally comment out the code in .bashrc and restart terminal before being able to elevate myself to root. I have no idea what this piece of code does frankly. Could anyone suggest either how to fix it or may be there's an easier way to accomplish this.
Many thanks!