提示变量中的特殊字符改变了吗?

Special characters in prompt variables changed?

我目前正在尝试通过我的新 Macbook Pro M1 了解有关 CLI 的更多信息,并尝试自定义我的提示。

在我的主目录中显示:

johndoe@Johns-MacBook-Pro ~ %

为了了解有关此提示的更多信息,我输入了:

echo $PS1  
// output: %n@%m %1~ %#

变量n和m不符合网上找到的解释:https://www.howtogeek.com/307701/how-to-customize-and-colorize-your-bash-prompt/

因为它们引用了以下环境变量列表:

根据这些来源,此命令:

PS1="\u:\w$ "

应该会出现以下提示:

user:working_directory$

变量似乎变了,字符也从 \ 变成了 %。 不幸的是,我找不到有关新变量的任何信息。

有没有人对此了解更多或有link解释?

您使用的是 zsh,而不是 bash。提示序列的描述是 在 zshmisc(1) 中解释(输入 man 1 zshmisc 也能看到)。为了 参考,它说:

   %n     $USERNAME.
   %m     The hostname up to the first `.'.  An integer may follow the `%'
          to  specify  how  many  components  of the hostname are desired.
          With a negative integer, trailing components of the hostname are
          shown.
   %~     As  %d  and %/, but if the current working directory starts with
          $HOME, that part is replaced by a `~'. Furthermore, if it has  a
          named  directory  as  its prefix, that part is replaced by a `~'
          followed by the name of the directory, but only if the result is
          shorter  than the full path; see Dynamic and Static named direc‐
          tories in zshexpn(1).