Find the answer to your Linux question:
Results 1 to 8 of 8
I want to get `echo xxx` output in color, what I have to do for that?...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37

    How to get output word in color

    I want to get `echo xxx` output in color, what I have to do for that?

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    You have to prefix the output with the 'escape sequence' that'll turn on the color and then postfix with the escape sequence' to turn the color off. For example, to print in blue:

    Code:
    _esc="\033"
    _blue="${_esc}[34m"
    _off="${_esc}[0m"
    echo "${_blue}xxx${_off}"
    Here's a link with the escape sequences:
    ANSI color codes

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    Thanks for the quick reply.........

    but for me your command dosnt work but when i used echo -en "yourcommand" it worked perfectly

    any way thanks alot i got wat i want....

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    can you pls explain me wat is the \033?

  5. #5
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    Sorry, forgot the -e option. That option does this:

    -e enable interpretation of the backslash-escaped characters listed below

    In this case:

    \NNN the character whose ASCII code is NNN (octal)

    033 is the octal value of the escape character.

  6. #6
    Just Joined!
    Join Date
    Oct 2008
    Location
    Edinburgh, Scotland
    Posts
    18
    You could also do:

    Code:
    echo -e '\E[37mYour text here' ; tput sgr0
    the ending resets the screen to original colours

    Change the ANSI codes to suit.

  7. #7
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    thanks for the reply........

  8. #8
    Just Joined!
    Join Date
    Oct 2008
    Location
    Edinburgh, Scotland
    Posts
    18
    You're most welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...