I want Input and Output to be different colors in a GNU or Linux bash terminal shell.

I use terminals all the time for bash, R, and python. Today I am fighting all day long to read my R and I have to manually put lots of CRLF to separate and find my place all the time.

So can you help me get terminal I/O to have different Input color and Output color?

  • What terminal client are you using? Feb 7, 2017 at 18:57
  • The client is the best place to set background colors. I use 6 different colors to distinguish between the machines I'm connected to. Feb 7, 2017 at 20:37
  • Could you please add examples of what you mean by "input" and "output" colors? The shell prompt? The command you're typing? The data printed by your application? A question asked by your application? An answer you're typing to that app? ...
    – egmont
    Feb 9, 2017 at 1:16

1 Answer 1


It's a bit of a hack, but you can set a DEBUG trap. From trap's documentation:

If a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command

You can set a TRAP which will echo ANSI color codes to the console (e. g. echo -e "\e[1;33;44m" which will change the color of output (notwithstanding any further changes by the output itself). You can also set PROMPT_COMMAND or PS1 to change the color of text which you input at the prompt for the purposes of differentiation.

  • This works perfectly, adding the input color to the end of PS1, then adding the trap on the next line to reset the output color, "trap 'tput sgr0' DEBUG" Sep 27, 2019 at 7:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .