默认的 root bash 提示符是什么?

What's the default root bash prompt?

在我的例子中,root bash 提示符是

[hostname dir]# in red

在我的 linux 系统中,我可以找到这个默认的 bash root 提示符是什么?我刚刚在 etc/skel/.bashrc

中找到默认 plain 用户 bash 提示

根据 OP 编辑。

查看ArtixLinux bash sourcePS1设置为:

PS1='[\u@\h \W]$ '
  • \u 用户名
  • \h 主机名(短)
  • \W 工作目录(基本名称)
  • $提示符

如果我们查看 ss64 bash syntax-prompt 页面,我们可以发现:

This change can be made permanent by placing the export PS1 definition in your ~/.bashrc file. To see what is currently defined in your .bashrc/.bash_profile use grep 'PS1' $HOME/.bash{rc,_profile}

The default value on many distros is '\s-\v$ '

所以默认的 PROMT 是:

  • \s:shell 的名称,$0 的基本名称(最后一个斜杠后面的部分)。
  • -:文字- 字符
  • \v:Bash的版本(例如,2.00)
  • $:如果你不是root,插入一个$;如果你是 root,你会得到一个 # (root uid = 0)
  • :文字 space

一旦用户登录系统,用户环境变量就会从各种文件中初始化:

/etc/profile or /etc/bashrc (system wide)
~/.bash_profile , ~/.bash_login , ~/.profile , ~/.bashrc or ~/.bash_logout (user)

gnu docs 告诉更多提示

您可以 customise/define 当前 shell 会话的提示临时方式

export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w$"

要使其永久粘贴到 .bashrc 中,然后 source .bashrc

for more customisation

首先,有一个配置选项可以在 PS1 字符串 --enable-prompt-string-decoding 中启用对反斜杠转义的解释,而且它很常见。

然后,许多发行版都带有这样的预设值,例如 Ubuntu:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]\w\[3[00m\]$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$ '
fi

如果未设置 PS1manual 会告诉我们

The default value is \s-\v$ .

看起来像 -bash-5.1$

我们还可以看到在config-top.hsource:

#define PPROMPT "\s-\v\$ "