Using escape codes directly is cool, but I'm a fan of using tput like this:
# SET Attribute Foreground <colour 123>kindalightblue=$(tput setaf 123)
There are a lot of handy things tput can do, and though the capabilities vary with your terminal, and though it's not completely portable either, you get all the colours your terminal can show.
Using escape codes directly is cool, but I'm a fan of using
tputlike this:There are a lot of handy things tput can do, and though the capabilities vary with your terminal, and though it's not completely portable either, you get all the colours your terminal can show.
I haven't heard about
tputbefore. I'll definitely check it out.EDIT: Just took a look. It's great. Thanks for the tip 🚀.
Thanks for the great article. However in my environment, if I run the example, it will print the escape code literally. e.g.
For me the solution is to use
printf, e.g.Try
$ echo -e "\033[32mRed text\e[0m". i.e.\e[32mRed text\033[0m
\033instead\e.This helped me as well in macOS. Thank you!
Try using
-nerather than-e.I have RED already in use, so had to do this:
Great article. Something that should be simple but is actually super hard to understand thank you
Glad to help.
If you want to see the colors you can use this script: gist.github.com/dtmilano/4055d6df5... which uses
tput.Thank you for the super helpful post.
I think the first example should be:
echo -e "\e[31mRed text\e[0m"32represents green.Thanks for noticing! Fixed it.
Just add '5' as a blinking special, non-colour code ;)
Great post!