Outputting Text with Colours using Bash and Other Scripting Languages
Last updated:HEADS-UP: When using languages other than bash, make sure you use the appropriate function that accepts escape sequences. For example, in ruby, you need to output text using
puts
otherwise the color codes won't be correctly parsed. This is equivalent to using-e
in bash.
Output text in colours
These messages work within any text printed to a console. They can therefore be used in other scripts you create (php, ruby, python, perl, etc), not just bash.(*)
In general, languages will only parse special characters (like
\033
if you use double-quotes).
Messages in uppercase are given as examples only.
red text
$ echo -e "\033[31mERROR:\033[00m"
yellow text
$ echo -e "\033[33mWARNING:\033[00m"
bold yellow text
$ echo -e "\033[1;33mWARNING:\033[00m"
bold green text
$ echo -e "\033[1;32mSUCCESS\033[00m"
References
Bash Tips: colors and formatting
- Very good post with lots of examples.
Felipe
TECHNOLOGY
cheatsheet
bash