This article describes how to use the environment variable PS1 color matching in Bash.
PS1 Introduction
PS1 is the abbreviation Prompt String 1, it is a message for environment variables to control under Linux / Unix, PS1 is interactive shell environment variables for controlling user input message, similar to environment variables as well as PS2, PS3 and PS4. About PS1 related to the introduction can be found in:
PS1 color matching
Format is as follows:
format:
\[\e[F;B;Cm\]
- F: Foreground color: the range of 30-37
- B: Background Color: in the range 40-47
- C: set style: the range of 0-8
Since the range can be seen that three different, so no problem of coincidence, can be judged from the value of the set content, so that setting the variable order. Foreground and background colors and color ranges described in the following table:
prospect | background | colour |
---|---|---|
30 | 40 | black |
31 | 41 | red |
32 | 42 | green |
33 | 43 | yellow |
34 | 44 | blue |
35 | 45 | Fuchsia |
36 | 46 | cyan |
37 | 47 | white |
Style C setpoint and the meanings shown in the following table
Code | significance |
---|---|
0 | OFF |
1 | Highlight bold |
4 | Underline |
5 | flicker |
7 | Highlight |
8 | Invisible |
Setting Example
Example:
PS1="\[\e[33;42;1m\h:\W \u\$\]"
Foreground color: yellow
background color: green
style: Bold highlighted
Execution results as shown below: