Linux登录过程中加载配置文件顺序:
/etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc],后面的文件配置应该会覆盖前面的
debian设置命令提示符配置文件:/etc/bash.bashrc;其他版本系统可能在/etc/profile,/root/.bashrc,/root/.profile等文件中可以设置。
PS1中设置字符颜色的格式为:,其中“F“为字体颜色,编号为30-37,“B”为背景颜色,编号为40-47。用 \e[m 结束颜色设置。
PS1='[\e[33;40m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ \e[0m' #加上\e[0m或者\e[m结束颜色设置,只是提示符为黄色,其他不受影响。
PS1='[\e[33;40m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' #把命令提示符设置成黄色,但输入的指令也是黄色,所有页面显示都是黄色。
PS1='[\e[36;40m\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ \e[m \e[33;40m\]' #把提示符框内设置成青蓝色,后面指令显示黄色,其中\e[m可有可无。
以上设置都会导致首行指令不会换行,会反过来覆盖提示符,都是因为颜色设置的部分没有使用来转义(颜色设置的每个位置都需要完整的括起来)。
再次执行一次指令就会出现不换行,直接覆盖提示符的情况:
解决方法是利用这一对符号完成包住颜色设置段,非打印的字段都需要这对符号圈住。
: begin a sequence of non-printing characters, which could be used to embed a terminal control sequence
into the prompt:end a sequence of non-printing characters)
最终设置为
最终效果:
自动换行: