1

I'm looking for a way to apply custom colors to messages emitted by the rm -i command:

~ $ rm -i file.txt
rm: remove regular empty file 'file.txt'?

I understand that I need to redirect the stderr as stdin to any command that will apply the ANSI colors to it and redirect the output back to stderr, e.g.

~ $ rm -i file.txt 2> >(sed $'s/^/\e[31m/;s/$/\e[m/'>&2)

However, this alone doesn't work; the above command doesn't print anything and starts to await the user input immediately. If I enter e.g. n and Enter, I get the colored output printed afterwards:

~ $ rm -i file.txt 2> >(sed $'s/^/\e[31m/;s/$/\e[m/'>&2)
n
rm: remove regular empty file 'file.txt'? ~ $ 

I seem to understand what is going wrong here - the stderr was redirected and colored, but not printed since the command started to await user input. Is there a way to print colored message before rm starts listening to the stdin?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.