Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • Lovin’ fromhex. Thanks again! Also, I added a check for the #. Feedback? Commented Mar 12, 2016 at 5:23
  • 1
    Yes, removing a leading '#' is a reasonable protection. I find a lot simpler to use hex=${1#"#"}. It will remove nothing if $1 does not have a #, and remove it if it exists. See my updated code. Commented Mar 12, 2016 at 7:03
  • Note that at least in my version of xterm the \e[0;%s8;2;%s;%s;%sm doesn't give me 16M colours, just the colour in the 240 colour palette that's closest to the requested rgb. Commented Mar 12, 2016 at 8:49
  • @StéphaneChazelas Yes, the 16 million color do not work on all consoles (that is the reason for the note I added right from the start). I added now an specific test in red to "see" the (very small) change with that option. The terminal for KDE Konsole does work with 16 million color. Commented Mar 12, 2016 at 21:39
  • 1
    -1 The answer doesn't use tput or show how it is used. I don't care if the entire world thinks printf is better it still doesn't address the OP's question nor why I ended up here. Commented Apr 5, 2024 at 14:07