I need to understand this code snippet that I found in .profile file

echo -en "\e[32;44m $(hostname) \e[m";echo -e "\e[m"

This snippet is used to print out the hostname of the system with a blue background and a green font.

To color your shell, you use special color escape sequences.

\e[ starts the color scheme, 32; will set the foreground color to green, 44 will set the background color to blue and m will end it.

$(command) creates a new shell, executes command and returns the result (not the return value).

hostname returns the hostname of the current system.

\e[m will reset the coloring of the output.

From the echo manpage:

   -n     do not output the trailing newline
   -e     enable interpretation of backslash escapes

IMHO your snippet could be simplified to echo -e "\e[32;44m $(hostname) \e[m";

See the chapter 6.1 Colours of the BASH Prompt HOWTO for more details.


see http://en.wikipedia.org/wiki/Control_Sequence_Introducer for more more details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.