Use the echo command to output a string with color and font formatting under Linux

Source: Internet
Author: User

echo Output Color font: Format Example:

Echo–e "\033[31m is changed font color character \033[0m"

where \033[31m began,

* where (3 of the start control foreground color) 1 is red, this value is replaced with 2 is green,3 Brown,4 Blue,5 Purple,6 bluish green

* background Color control string starting with 4

* Single character set font (1 is bold, 4 is underline;5 is blinking;7 reverses foreground, background)

Example:1;

\033[0m End

The format is as follows (# # represents numbers, where 3#;4#;# can write only one or several items! Must have the end character, otherwise the terminal after the display of characters are like this! Start character ends with m)

Echo-e "\033[3#;4#; #m character \033[0m changed font color "

This can be used in scripts:

Red= ' \033[31m '

Ter= ' \033[0m '

Echo-e "${red}hello${ter}"

/etc/sysconfig/init

/etc/init.d/functions---- Red Hat Many scripts call the function function of this 2 file! Read these 2 files to learn more about Shell programming skills!

Move character display:echo–e "\033[40gabc" #40 represents the number of characters moved from left to right, and then displays the ABC

Startup in the service script, and so on, the successful execution of the [OK] display:

Echo-n "Starting testservice ..." echo-e "\033[60g [\033[32mok \033[0m]"

*) regardless of the number of preceding control characters, there is only one end character.


This article from the "Let me more Hungry" blog, please be sure to keep this source http://ufirst.blog.51cto.com/7628670/1432615

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.