Use echo to display colored content in shell scripts

Source: Internet
Author: User
Tags clear screen set background

Using echo to display colored content in a shell script requires the use of the parameter-E

The format is as follows:

" \033[Word background color; text color m string \033[0m"

For example:

" \033[41;36m Hello World \033[0m"

Where 41 of the position represents the background, 36 of the position is the color of the word
Note:
1, the word background color and the text color is in English ""
2. There is a m behind the text color
3, before and after the string can have no space, if any, the output is also a space
Here is the corresponding word and background color, you can try to find out the different color collocation

For example:

" \033[31m Red Word \033[0m""\033[33m yellow word \033[0m""  \033[41;33m Red Bottom yellow \033[0m""\033[41;37m Red Bottom white letter \033[0m "

Word Color: 30-37

Echo-e"\033[30m Black character \033[0m"Echo-E"\033[31m Red character \033[0m"Echo-E"\033[32m Green Word \033[0m"Echo-E"\033[33m Yellow Word \033[0m"Echo-E"\033[34m Blue character \033[0m"Echo-E"\033[35m Purple character \033[0m"Echo-E"\033[36m Sky blue character \033[0m"Echo-E"\033[37m White character \033[0m"

Word background color range: 40-47

Echo-e"\033[40;37m Black Bottom white \033[0m"Echo-E"\033[41;37m Red Bottom white \033[0m"Echo-E"\033[42;37m Green Bottom white \033[0m"Echo-E"\033[43;37m Yellow \033[0m"Echo-E"\033[44;37m Blue Bottom white \033[0m"Echo-E"\033[45;37m white \033[0m on purple background"Echo-E"\033[46;37m Blue Bottom white \033[0m"Echo-E"\033[47;30m Black character \033[0m on white background"

Last Face Control option Description:

\ -[0m close all properties \ -[1m set high brightness \ -[4m underline \ -[5m blinking \ -[7m reverse display \ -[8m blanking \ -[30m-\ -[37m set foreground color \ -[40m-\ -[47m set background color \ -[NA cursor moves up n rows \ -[NB cursor moves down n lines \ -[NC cursor shifts right n rows \ -[ND cursor moves left n rows \ -[y;xh set cursor position \ -[2J clear screen \ -[K clears the contents from the cursor to the end of the line \ -[s save cursor position \ -[u restore cursor position \ -[?25lHide cursor \ -[? 25h display cursor

Use echo to display colored content in shell scripts

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.