Skip to content
Advertisement

Colorizing echo works in Solaris but doesn’t work in Linux

I have 2 different servers where I log in with same network user and run the same script. One is Solaris and another is Linux.

Sample echo line from the script works differently on those servers:

JavaScript

In Solaris -> it displays the text “auto update” correctly in green

In Linux -> it displays the text incorrectly and with no color coding: “33[1;32mauto update33[m”

.bashrc profile has the following line for PS1:

JavaScript

Grateful if you can help me getting the color thing work in Linux. Thanks

Advertisement

Answer

This is a good illustration of why echo is not considered portable.

On dash and Solaris sh:

JavaScript

On bash, ash and ksh:

JavaScript

You can instead use printf:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement