DEV Community

Discussion on: Adding colors to Bash scripts

Collapse
 
jianwu profile image
jianwu

Thanks for the great article. However in my environment, if I run the example, it will print the escape code literally. e.g.

$ echo -e "\e[32mRed text\e[0m"
\e[32mRed text\e[0m
Enter fullscreen mode Exit fullscreen mode

For me the solution is to use printf, e.g.

echo -e $(printf "\e[32mRed text\e[0m")`
Enter fullscreen mode Exit fullscreen mode
Collapse
 
absoftware profile image
Ariel Bogdziewicz

This helped me as well in macOS. Thank you!

Collapse
 
sombody101 profile image
Sombody101

Try using -ne rather than -e.

Collapse
 
toransahu profile image
Toran Sahu

Try $ echo -e "\033[32mRed text\e[0m"
\e[32mRed text\033[0m
. i.e. \033 instead \e.