(go) shell script output with color font

Source: Internet
Author: User
Tags clear screen set background

Shell script output with color font

Original: http://blog.csdn.net/andylauren/article/details/60873400

Output Effect Format control:
\033[0m Close All Properties
\033[1m Setting High Brightness
\03[4m Underline
\033[5m flashing
\033[7M Reverse Display
\033[8m blanking
\033[30m--\033[37m setting foreground color
\033[40m--\033[47m Set background color

Formatting controls such as cursor position:
\033[na the cursor to move n rows
\03[NB cursor down n rows
\033[NC cursor right shifts n rows
\033[nd cursor left n rows
\033[Y;XH Setting the cursor position
\033[2J Clear Screen
\033[k clears the contents from the cursor to the end of the line
\033[s Save Cursor position
\033[u Restore cursor Position
\033[?25l Hide Cursor

\33[?25h Display cursor

Finishing:
Coded Color/action
0 Reset properties to default settings
1 setting Bold
2 Set half brightness (simulates color of color display)
4 Set underline (simulates color of color display)
5 Setting flashes
7 Setting the reverse image
22 Setting general Density
24 Turn underline off
25 Flashing off
27 Turn off reverse image
30 setting Black foreground
31 set Red foreground
32 Setting Green foreground
33 Setting Brown foreground
34 Set Blue Foreground
35 Setting Purple foreground
36 Setting the Cyan foreground
37 Setting White foreground
38 underline on the default foreground color
39 Turn the underline off on the default foreground color
40 Setting a black background
41 Setting the red background
42 Setting the green background
43 Setting the brown background
44 Setting the blue background
45 Setting purple Background
46 Setting the Cyan background
47 Setting a white background
49 Setting the default black background
Special effects can be superimposed, need to use ";" Separate, for example: Flashing + underline + white background + black word for \033[5;4;47;30m flashing + underline + white background + black word for \033[0m
Here is a small example

[Plain]View PlainCopy
    1. #!/bin/bash
    2. #
    3. #下面是字体输出颜色及终端格式控制
    4. #字体色范围: 30-37
    5. Echo-e "\033[30m Black character \033[0m"
    6. Echo-e "\033[31m Red word \033[0m"
    7. Echo-e "\033[32m Green word \033[0m"
    8. Echo-e "\033[33m Yellow word \033[0m"
    9. Echo-e "\033[34m Blue word \033[0m"
    10. Echo-e "\033[35m Purple word \033[0m"
    11. Echo-e "\033[36m sky blue Word \033[0m"
    12. Echo-e "\033[37m White character \033[0m"
    13. #字背景颜色范围: 40-47
    14. Echo-e "\033[40;37m Black Bottom White \033[0m"
    15. Echo-e "\033[41;30m Red Bottom black character \033[0m"
    16. Echo-e "\033[42;34m Green bottom Blue character \033[0m"
    17. Echo-e "\033[43;34m Yellow blue character \033[0m"
    18. Echo-e "\033[44;30m Blue bottom black character \033[0m"
    19. Echo-e "\033[45;30m black character \033[0m on purple background"
    20. Echo-e "\033[46;30m Blue sky \033[0m Black character"
    21. Echo-e "\033[47;34m White bottom Blue character \033[0m"
    22. #控制选项说明
    23. #\033[0m Close All Properties
    24. #\033[1m Setting High brightness
    25. #\033[4m Underline
    26. Echo-e "\033[4;31m underline red character \033[0m"
    27. #闪烁
    28. Echo-e "\033[5;34m Scarlet letter in flashing \033[0m"
    29. #反影
    30. Echo-e "\033[8m blanking \033[0m"
    31. #\033[30m-\033[37m Setting the foreground color
    32. #\033[40m-\033[47m Setting the background color
    33. #\033[na the cursor to move n rows
    34. #\033[nb cursor down n rows
    35. ECHO-E "\033[4A cursor up 4 lines \033[0m"
    36. #\033[nc cursor right shifts n rows
    37. #\033[nd cursor left n rows
    38. #\033[y;xh Setting the cursor position
    39. #\033[2j Clear Screen
    40. #\033[k clears the contents from the cursor to the end of the line
    41. Echo-e "\033[k clear the cursor to the end of the line \033[0m"
    42. #\033[s Save Cursor position
    43. #\033[u Restore cursor Position
    44. #\033[?25| Hide Cursor
    45. #\033[?25h Display cursor
    46. ECHO-E "\033[?25l hidden cursor \033[0m"
    47. ECHO-E "\033[?25h display cursor \033[0m"

(go) shell script output with color font

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.