Changing Text Color in-Line?
Short Question: Using Bash, Is It Possible to Print a Sentence Such That Each Individual Word Has a Different Color? I. E; Print a Word in-Line, Change the...
Short question:
Using bash, is it possible to print a sentence such that each individual word has a different color?
I.e; print a word in-line, change the text color, repeat?
1 Answer
ANSI escape sequences
You can use ANSI escape sequences. It should work in text screens as well as most linux terminal window emulators.
See this link for details,
Example 1: White text on black background
echo -e "\0033[37;40m###############\0033[0m"
Example 2: Black text on greyish white background
echo -e "\0033[30;47m###############\0033[0m"
Example 3: Using the variables inversvid, greenback, blueback and resetvid
inversvid="\0033[7m"
resetvid="\0033[0m"
greenback="\0033[1;37;42m"
blueback="\0033[1;37;44m"
echo -e "$inversvid Now it is inverse colours $resetvid"
echo -e "$greenback Now it is greenback $resetvid and $blueback now blueback $resetvid"