• Welcome to Bashguru

    Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. It's functionality list is quite similar to that of UNIX and become very popular over the last several years. Our Basic motive is to provide latest information about Linux Operating system.

  • Python Programming

    Python is a comparatively simple programming language, compared to c++. Although some of the benefits of c++ are abstracted away in python, they are replaced with an overall easier to learn language with many “intuitive” features. For this reason it is common and recommended by most professionals that people new to programming start with python.

  • Perl Programming

    Perl is an open-source, general-purpose interpreted programming language. Used often for CGI, Perl is also used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. The Perl languages borrow features from other programming languages including C, shell scripting (sh), AWK, and sed. They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary UNIX command line tools, facilitating easy manipulation of text files.

  • Android

    Android is an operating system based on the Linux kernel, and designed primarily for touch screen mobile devices such as smart phones and tablet computers. Android is a Linux-based software system, and similar to Linux, is free and open source software. This means that other companies can use the Android operating developed by Google and use it in their mobile devices.Android gives you a world-class platform for creating apps and games for Android users everywhere, as well as an open marketplace for distributing to them instantly.

Friday, January 1, 2010

Posted by venu k
66 comments | 2:17 AM
 Shell scripts commonly used ANSI escape codes for color output.
Following table shows Numbers representing colors in Escape Sequences.
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47
The numbers in the above table work for xterm terminal.Result may vary for other terminal emulators. Use the following template for writing colored text. echo -e "\033[COLORm Sample text" The "\033[" begins the escape sequence.You can also use "\e[" instead of "\033[". COLOR specifies a foreground color, according to the table above.The "m" terminates escape sequence, and text begins immediately after that.
Note: With an echo, the -e option enables the escape sequences.You can
also use printf instead of echo.
printf "\e[COLORm sample text\n" To print Green text echo -e "\033[32m Hello World" or printf "\e[32m Hello World" The problem with above statement is that the blue color that starts with the 32 color code is never switched back to the regular color, so any text you type after the prompt and even prompt also is still in the Green color. To return to the plain, normal mode, we have yet another sequence. echo -e "\033[0m" Now you won't see anything new on the screen, as this echo statement was not passed any string to display. But it has done its job, which was to restore the normal viewing mode. Whatever yor type now will be avoid of any fancy effects. Escape sequence also allow you to control the manner in which characters are displayed on the screen. The following table summarizes numbers representing text attributes in Escape Sequences.
0Normal Characters
1Bold Characters
4Underlined Characters
5Blinking Characters
7Reverse video Characters
Note: Blink attribute doesn't work in any terminal emulator, but it
will work on the console.
Combining all these Escape Sequences, you can get more fancy effect. Use the following template for writing colored text on a colored background. echo -e "\033[COLOR1;COLOR2m sample text\033[0m" The semicolon separated numbers "COLOR1" and "COLOR2" specify a foreground and a background color.The order of the numbers does not matter, since the foreground and background numbers fall in non- overlapping ranges."m" terminates the escape sequence, and the text begins immediately after that.Although setting the colors separately also work (i.e. \033[44m\033[32m). There are some differences between colors when combining colors with bold text attribute. The following table summarises these differences.
Bold offcolorBold oncolor
0;30Balck1;30Dark Gray
0;31Red1;31Dark Red
0;32Green1;32Dark Green
0;34Blue1;34Dark Blue
0;35Magenta1;35Dark Magenta
0;36Cyan1;30Dark Cyan
0;37Light Gray1;30White
The following shell script prints all the colors and codes on the screen.

# This script echoes colors and codes
echo -e "\n\033[4;31mLight Colors\033[0m \t\t\033[1;4;31mDark Colors\033[0m"
echo -e "\e[0;30;47m Black \e[0m 0;30m \t\e[1;30;40m Dark Gray \e[0m 1;30m"
echo -e "\e[0;31;47m Red \e[0m 0;31m \t\e[1;31;40m Dark Red \e[0m 1;31m"
echo -e "\e[0;32;47m Green \e[0m 0;32m \t\e[1;32;40m Dark Green \e[0m 1;32m"
echo -e "\e[0;33;47m Brown \e[0m 0;33m \t\e[1;33;40m Yellow \e[0m 1;33m"
echo -e "\e[0;34;47m Blue \e[0m 0;34m \t\e[1;34;40m Dark Blue \e[0m 1;34m"
echo -e "\e[0;35;47m Magenta \e[0m 0;35m \t\e[1;35;40m DarkMagenta\e[0m 1;35m"
echo -e "\e[0;36;47m Cyan \e[0m 0;36m \t\e[1;36;40m Dark Cyan \e[0m 1;36m"
echo -e "\e[0;37;47m LightGray\e[0m 0;37m \t\e[1;37;40m White \e[0m 1;37m"
Some examples:
Block background and white text echo -e "\033[40;37m Hello World\033[0m" Reverse video text attribute option interchanges fg and bg colors. Bellow statement prints block on white echo -e "\033[40;37;7m Hello World\033[0m" echo -e "\033[33;44m Yellow text on blue background\033[0m" echo -e "\033[1;33;44m Bold yellow text on blue background\033[0m" echo -e "\033[1;4;33;44mBold yellow underlined text on blue background\033[0m" The "tput" command: Other than echo there is a command called tput using which we can control the way the output is displayed on the screen.But it is less flexible than ANSI escape sequences.


  1. Replies
    1. 什么叫惨败是什么意思?

  2. Hi. This was excellent info indeed, thanks so much for your help!

    I would like to pipe all my output to a file and retain the color settings using >>

    Any ideas how to do that please?

  3. hi this is a nice post, was actually going to put up a post on it my self, but as you have such a well written post on it, will be providing a link to your post in my post. Hope that is fine.

  4. Awesome Thanks for sharing really helpful

  5. Amazing blog dude, Its in my opinion best blog for bash script related things, I really love your examples and scripts and more importantly your explanation, I have now added you as google friend and will look forward for more quality articles and tips.

    10 examples of using VI Editor in UNIX

  6. It's very nice explained making very easy to understand this topic for bash.
    Thank you!

  7. thanks a lot was use-full for me

  8. I am writing my scripts now colorfully.
    Thank you very much.

  9. Thank u very much . . .

  10. Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.
    Vee Eee Technologies

  11. Hi i am S.Abdul Kareem
    Really This is web site very nice ....
    Thank you..... Very Much Up-loaders

  12. Really Helpful. Thanks

  13. This is very helpul. But when i am trying to send a coloured text file via mail then output comes withour colours.

    Can you plz help.

  14. Thank you! This should really be the number one result when searching for: Color bash output. But, as the eighth result... you were the only helpful one!

    Note: I didn't clearly get the underline from above. I found that you can do your two colors and then the attribute you want. [color1;color2;attributem
    (the 'm' still escapes)

  15. This is great, very helpful.

    I was able to use this to highlight different fields in a log file using AWK:

    tail -f LOGFILE | while read LINE; do echo "$LINE" | awk -F'\t' '{ printf "%-20s %40s %20s %s %s %s %s %s\n", "\33[0;32;40m" $1 "\33[0m",$7,"\33[37m"$13"\33[36m",$14,$19,$21,$22,"\33[35m"$24 }'
    ; done

    (I had to do the read/echo bit because tail-f wouldn't work otherwise. Is there a better way around that?)

  16. This is absolutely beneficial, thank you so much

  17. Nice post. Thanx a ton. Keep posting stuff like this..

  18. I love Balck, it's my favorite color.

  19. Thank You.. Dharmin

  20. thank you .... really helpful

  21. Thanks man!

    A very helpful article.

    I had a lot of fun playing with those colors.

  22. Gracias!.. very useful.


  23. Very easy, thanks :D

  24. Hi All ..need help ...

    while running this command on console :

    echo -e "\e[;32m Hello World\e[0m"

    getting output in green color , but when I am trying to save this in file , output in the file is like this

    ^[[;32m Hello World^[[0m

    Can anyone please help out?

  25. It helped me to beautify my shell script utility

  26. Great idea and this article tell us how maintain your shell scripts and how to update time and date when any issue in shell script thanks for sharing personal statement review service .

  27. If you need any tips on writing you can take a look at this page to improve your writing skills.


  28. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball game |

  29. I truly love your website.. Excellent colors & theme.

    Did you build this site yourself? Please reply back as I’m looking to create my own blog
    and would like to find out where you got this from or just what
    the theme is called. Kudos!

  30. Wonderful work! This is the type of info that should be shared around the internet.

    Shame on the seek engines for now not positioning this post upper!
    Come on over and consult with my site . Thanks

  31. Hello there! This article couldn’t be written any better!
    Looking at this post reminds me of my previous roommate!
    He continually kept talking about this. I most
    certainly will forward this post to him. Pretty sure he will have a good read.

    Thank you for sharing!

  32. Great web site. A lot of helpful information here.
    I am sending it to several buddies ans additionally sharing in delicious.
    And naturally, thanks on your effort!

  33. Hi mates, its fantastic article about cultureand entirely explained, keep it up all the time.

  34. I pay a visit day-to-day some websites and blogs to read posts,
    except this website provides quality based content.

  35. Hey there are using WordPress for your site platform?
    I’m new to the blog world but I’m trying to get started and set up
    my own. Do you need any coding expertise to make your own blog?
    Any help would be greatly appreciated! Jual Boneka Wisuda | Jaket Bomber Pria

  36. I've read all your information that you shares in your article and I really love it. Thank you for sharing this post. I appreciate it.
    - five nights at freddy's

  37. I would like to thank you for the efforts you have made in writing this post.
    - twitter search

  38. The game is best known for its dark sense of humor and its graphic violence. Expect to see a lot of blood and guts. Your goal is to go far across each level without letting your character get hurt. The game is over even the smallest body part injuries. It takes much patience to finish the goal. Is this much challenging? Make your best efforts to survive in this glory and funny game. We can find a way to break through Even if we can't find heaven, I'll walk through hell with you.
    geometry dash
    happy wheels

  39. Galaxy S9 launch a new smartphone with new technology Galaxy S9.

  40. A debt of gratitude is in order for sharing supportive data, I truly like your everything post. I will bookmark your blog for future updates.
    High Profile D​elhi Modern Cal​l Girls
    Hot Escorts in​ Delhi

  41. urm web solutions is a leading Seo company in noida.

  42. For some students it may be really difficult to write an essay. However they can overcome the difficulties by ordering an essay from https://thepaperwriting.com/research-paper-writing.

  43. This comment has been removed by the author.

  44. This comment has been removed by the author.

  45. this is the great website for the color scripts
    Best SEO Company in Noida


  46. MBA Distance
    Thank you so much for sharing this amazing article with us.Will stay connected with your blogs for the future posts.

  47. Great post keep up the good work. Thank for share amazing blog..
    Online MBA

  48. online courses in india
    An obligation of appreciation is all together to share steady information, I really like your beginning and end post. I will bookmark your blog for future updates.

  49. This is very good content you share on this blog. it's very informative and provide me future related information.
    Online MBA

  50. Thank you for sharing this post. I appreciate it. I really like your beginning and end post. we are mobile app development company NYC and again Thank you for sharing!

  51. Online certification courses in india
    I extremely cherished perusing your blog. I likewise discovered your posts extremely intriguing. Actually in the wake of understanding, I needed to go demonstrate it to my companion and he ejoyed it also!