I have configured gnome-terminal in .bashrc to have custom colours:

PS1='${debian_chroot:+($debian_chroot)}\[\033[00;37m\][\[\033[00;32m\]\t\[\033[00;37m\]] \[\033[01;34m\]\u\[\033[00;37m\]@\[\033[01;34m\]\h\[\033[00;37m\]:\[\033[01;34m\]\w\[\033[01;32m\]$ '

And this means that when executing something like this:

enter image description here

The output looks like this even though the first line should be white, and was white until I made the command that is typed in also green:

enter image description here

So how can I make the output text colour not be affected by the fact that I have set the command colour to be green? I am running Ubuntu GNOME 15.04 with GNOME 3.16.

Information Update:

I have noticed that when running sudo rkhunter --nocolor --update the output is all green.

  • 1
    Just the output of the command or also the text you type in the prompt? – kos Oct 15 '15 at 13:52
  • What may be happening is that since rkhunter has its own set of color setups, it is going to be trying to use the last stated color, since it doesn't apply color formatting to its first line. If you changed your PS1 so that your commands are in green, that 'color' line hasn't been overridden yet so it won't 'stop' printing in that color until it receives a "Clear Formatting" type of escape char. Here's the test: run sudo rkhunter --nocolor --update and see if everything is in green. – Thomas Ward Oct 15 '15 at 13:58
  • @ThomasW.: Ok, I have tested that command and then all the text is green. – user364819 Oct 15 '15 at 14:02
  • 2
    @ParanoidPanda then the issue is because you left PS1's color escape codes open so the command entry is formatted. Since rkhunter doesn't apply color formatting until that third line in your output, there's nothing to override the color formatting to set it back to white. There's no easy way to fix that, I think. (See chat) – Thomas Ward Oct 15 '15 at 14:04
  • @ThomasW.: Is there any way to fix that at all? – user364819 Oct 15 '15 at 14:06

The problem is that you are setting the command to be in green but are not closing the color escape code. Therefore, all subsequent lines, including the output of any commands which do not have their own formatting applied, are shown in that color. As a workaround (source), you could trap printing the close code to the DEBUG signal. Add this line to your ~/bashrc

trap 'printf "\e[0m" "$_"' DEBUG

That will print \e[0m (which will close the open color code). Because it is trapped to the DEBUG signal, it will be executed before any command you run. So, between hitting Enter and the command actually running. As explained in man bash:

If a sigspec is DEBUG, the command arg is executed before every simple command, for command, case command, select command, every arithmetic for command, and before the first command executes in a shell function (see SHELL GRAMMAR above).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.