Set the shell script output font color

Source: Internet
Author: User
Tags clear screen echo command

Echo-e "/033 [32; 49; 1 m [done]/033 [39; 49; 0 m"
Output result: [done]
###########################
The color of the text terminal can be generated using an ANSI unconventional character sequence. Example:

Echo-e "/033 [44; 37; 5 m me/033 [0 m Cool"

The above command sets the background to blue, foreground white, blinking cursor, output character "me", then reset the screen to the default settings, and output the character "cool ". "E" is an option for the echo command, which is used to activate the parser for special characters. "/033" leads the sequence of unconventional characters. "M" means setting the attribute and ending the unconventional Character Sequence. In this example, the valid characters are "44; 37; 5" and "0 ".

Modify "44; 37; 5" to generate a combination of different colors. The values are irrelevant to the order of encoding. The optional encoding is as follows:

Encoding color/Action
0. Reset the property to the default setting.
1. Set bold
2. Set half brightness (simulate color display)
4. Set the underline to simulate the color of the color display)
5. Set flashing.
7. Set reverse Images
22. Set the general density
24. Close the underline
25 turn off flashing
27 disable reverse image
30 set the black foreground
31 set the red foreground
32. Set the green foreground
33 set the brown foreground
34 set the blue foreground
35 set purple foreground
36 set the blue foreground
37 set the white foreground
38. Set the underline on the default foreground color
39. Disable the underline on the default foreground color
40 set a black background
41 set the red background
42 set a green background
43 set brown background
44 set the blue background
45 set a purple background
46 set the blue background
47 set the white background
49 set the default black background


Other interesting code:

/033 [2j clear screen
/033 [close all keyboard lights with 0q
/033 [1q: Set the "scroll lock" indicator (scroll lock)
/033 [set the "value lock" indicator (num lock) for 2q)
/033 [set "Caps Lock" for 3q)
/033 [15: 40 h move close to 15th rows, 40 Columns
/007 beep

#######################
How to change the font and background color of RedHat:
Command:
PS1 = "[/E [32; 1 m/u @/h/W] // $"
Or
Export PS1 = "[/E [32; 1 m/u @/h/W] // $" for the differences between the two, please refer to the relevant information about environment variables.
Explanation:
/E [32; 1 M: This is the escape character that controls the font and background color, 30 ~ 37 is the font color, 40 ~ 47 is the background color
In the example, the 32; 1 m digit position can be reversed, for example,/E [1; 32 M. If it is in the X environment, you can change the range of 1 to 0 ~ 10, some useless places: 0 or do not write (/E [0; 32 m or/E [; 32 m) Show light color, 1: Show highlighted 4: underline ..... if the effect is not good but cannot be restored, do not write the number before m, for example,/E [32; m, or log out directly before logging in.
/U/h/W: these are some escape characters, which are explained in detail below:
/D: represents the date, in the format of weekday month date, for example: "Mon Aug 1"
/H: complete host name. For example, if my machine name is fc4.linux, this name is fc4.linux.
/H: only the first name of the host. In the preceding example, the name is FC4, and the name of. Linux is omitted.
/T: The display time is in the 24-hour format, for example, HH: mm: Ss.
/T: The display time is 12 hours.
/A: The display time is in the 24-hour format: hh: mm
/U: Account name of the current user
/V: Bash version information
/W: complete working directory name. In the home directory ~ Replace
/W: Use basename to get the working directory name. Therefore, only the last directory is listed.
/#: Commands issued
/$: The prompt character. If it is root, the prompt is: #, and the normal user is: $
/N: Create a new row.
The font is not limited to one color. It can have multiple colors:
PS1 = "[/E [32; 1 m/u @/E [35; 1 m/h/E [31; 1 m/w] // $"
The preceding two Commands will expire after logging out. Use the following method to make them permanently effective:
VI/etc/profile
Add a line under "Export path...": Export PS1 = "[/E [32; 1 m/u @/h/W] // $"
Log out and log on again. If it does not take effect, run the source/etc/profile command or restart the machine.

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.