Bash PS1 提示中的长行重叠 [英] Long lines overlap in Bash PS1 prompt

查看:31
本文介绍了Bash PS1 提示中的长行重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了 PS1 bash 提示符.

I have configured a PS1 bash prompt.

我的~/.bashrc文件:

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?

推荐答案

在 bash 提示中使用非打印字符时,必须使用 将非打印序列(例如颜色代码)指定为非打印\[...\]:

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\] '

这篇关于Bash PS1 提示中的长行重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆