• Uncategorized

About linux : How-to-change-color-of-bash-output

Question Detail

I’ve tested:

echo "${RED}Print red"
echo "Print blue"

But the below text will be printed both in red even if only the first line has the variable
Same happens if I use:

tput setaf 4; echo "Print blue"
echo "Print Magenta"

It will be printing all my following terminal code in blue

I just want to change the color of a single line of code, saying an echo, for example, and nothing else.

Question Answer

In order to print a single line, you need to unset the color that has been set. Using tput

$ echo "$(tput setaf 4)Print Blue$(tput sgr 0)"

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.