Trying to color my command output, I am stuck in understanding the difference between

  • logging into my machine and seeing the MOTD
  • running run-parts on /etc/update-motd.d/

I created this test-script to illustrate:

echo -e "This is a test for ${G}GREEN${W} and ${R}RED${W}"
echo -e "Lets highlight some colors aight?" | grep --color 'ight'

When I run it directly, both lines have colors.

root@server:/etc/update-motd.d# ./test-file

When I run it via run-parts, both lines have colors.

root@server:/etc/update-motd.d# run-parts ./

BUT when I log in, only the first line gets colored!

How can I have colored greps or even debug this?


When you log in there is no run-parts /etc/update-motd.d. The run-parts happens from time to time, non-interactively, to update /etc/motd.

By default grep doesn't show colors when running non-interactively (for good reason). You may try grep --color=always, possibly TERM=xterm grep --color=always.

Use sudo update-motd(8) to update /etc/motd immediately and see the updated file.

  • Thanks, that helped perfectly. The issue was me using --color instead of --color=always. – TacoV Nov 21 '19 at 20:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.