Long lines overlap in Bash PS1 prompt

本秂侑毒 提交于 2021-02-08 07:47:04

问题


I have configured a PS1 bash prompt.

My ~/.bashrc file:

if [[ $EUID -ne 0 ]]; then
        PS1='\n\e[0;33m☛ \W\e[0m \n\e[1;35m⤷\e[0m '
fi

The problem is that the new line overlaps the previous one. Any idea how to fix this?


回答1:


When using non-printing characters in a bash prompt, you have to specify non-printing sequences (e.g. color codes) as non-printing, using \[...\]:

PS1='\n\[\e[0;33m\]☛ \W\[\e[0m\] \n\[\e[1;35m\]⤷\[\e[0m\] '


来源:https://stackoverflow.com/questions/17306348/long-lines-overlap-in-bash-ps1-prompt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!