Open ~/.BASHRC to see what the command prompt is: \[email protected]\h\w\$
\u represents the user name, \h represents the host name, \w represents the current directory, \$ represents a command prompt (ordinary user $, Super User #)
This command prompt is a bit long, very in the way, \[email protected]\h can be deleted, only show \w\$ is very good
Instead: ps1= ' \[\033[1;3;32m\]\w\[\033[31m\]\$\[\033[0m\] '
If you change to ps1= ' \033[1;3;32m\]\w\033[31m\]\$\033[0m\] ', the system will incorrectly understand the length of the string, causing the system to understand the position of the cursor wrong, There will be a long command back to the beginning of the situation. The following link is particularly clear about this issue http://mywiki.wooledge.org/BashFAQ/053#CA-3f52bac3b5ad40d98d0fa76a95be9049141bfced_5
The escape character must be placed between \[and \], and this rule applies only when defining PS1. In other places, the escape sequence is placed between \001 and \002.
About color escaping, run the following script and know it all.
#!/bin/bashcat << haha You can write like this: \033[one;two;three m this is called ANSI color. "ECHO-E" can use escapes! For more infomation, try "mans echo" Haha#character attributesa= (normal 0 Bold 1 Dim 2italic 3under 4blink 5six 6revert 7con Ceal 8delete 9) #forecolorb = (Black 30red 31green 32yellow 33blue 34magenta 35cyan 36white pns) #backcolorc = (Black 40re D 41green 42yellow 43blue 44magenta 45cyan 46white) function Show () {while Test $#-gt 0;doecho- E "\033[${2}m Weidia o\033[0m "| column-tshift 2done}show ${a[*]}echo ===============fore color ======================show ${ B[*]}echo ================back color ====================show ${c[*]}echo ================random =================== =====echo-e "\033[${b[3]};${c[1]}m Weidiao is great\033[0m"
Linux terminal change prompt