Home > Blockchain >  How to change color of bash output?
How to change color of bash output?

Time:04-12

I've tested:

RED='\033[0;31m'
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.

CodePudding user response:

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)"
  • Related