I'm embarrassed to ask this question, since there have been so many postings on the topic, but the discussions in them have been way above my paygrade, and I'm hoping somebody could give a really simple answer. I understand that /usr/bin/xterm
can in fact support 256 colors (in spite of the fact that tput colors
returns 8). But I'm been unable to generate more than 8 custom colors. For me the most understandable posting on this subject was by @alex, in this thread.
He gave this example:
fg_black="$(tput setaf 0)"
fg_red="$(tput setaf 1)"
fg_green="$(tput setaf 2)"
fg_yellow="$(tput setaf 3)"
fg_blue="$(tput setaf 4)"
fg_magenta="$(tput setaf 5)"
fg_cyan="$(tput setaf 6)"
fg_white="$(tput setaf 7)"
reset="$(tput sgr0)"
and then
echo -e "${fg_red} Red ${fg_green} Bull ${reset}"
did what you would expect Red in red and Bull in green.
Since xterm
can support more than 8 colors I would have thought that, for example,
fg_purple="$(tput setaf 125)"
should give me a purple color and that
echo -e "${fg_purple} Purple ${fg_green} Bull ${reset}"
would return a purple bull. But I cannot for the life of me get any number beyond 7 to produce a color different from the xterm's default foreground color. Is there a simple way to accomplish this?
Thanks for any advice.
0 Answers