PS1 env 无法在新 Mac Catalina 上解析

Pol*_*ris 8 macos shell ps1

我的 PS1 变量无法正确解析,看起来像这样,

\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]mv .bashrc .bash_profile
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]source .bash_profile
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]ls
Applications    Desktop     Documents   Downloads   Google Drive    Library     Movies      Music       Pictures    Public
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]vim .bash_profile
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]source .bash_profile
\[\e[;31m\][\u@\h \W]$ \[\e[m\]
\[\e[;31m\][\u@\h \W]$ \[\e[m\]
\[\e[;31m\][\u@\h \W]$ \[\e[m\]
\[\e[;31m\][\u@\h \W]$ \[\e[m\]
Run Code Online (Sandbox Code Playgroud)

发生了什么?谢谢。

Ell*_*otM 14

我在使用全新的 Catalina 机器时也遇到了这个问题。新模型似乎默认为zshshell 而不是传统的bash,以改变这一点:

转到Users & Groups(解锁以进行管理员更改)右键单击您的管理员用户Advanced Options...,更改Login shell/bin/bash

右键单击用户后

这将允许您利用 bash 的提示字符串解析来获得更好的提示——因为 mac 过去一直支持。