PS1 env cannot parse on the new mac Catalina
Asked Answered
N

1

9

My PS1 variable cannot parsed correctly, it looks like this,

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

What is happened? Thanks.

Norway answered 1/12, 2019 at 3:18 Comment(11)
Did you end up with that in PS1 on purpose? That very much looks like the result of an unfortunate accident. You should not have mv .bashrc .bash_profile or source .bash_profile, etc.. In fact, you should normally choose just one of the lines \[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\] or \[\e[;31m\][\u@\h \W]$ \[\e[m\]. Personally, I prefer PS1="\[\e[1;30m\]\D{%R}\[\e[1;34m\] \h:\w> \[\e[0m\]". To fix things just choose the prompt you will use and type PS1="yourprompthere" on the command line. Then edit .bashrc and find export PS1="...." and fix there.Brey
@DavidRankin-ReinstateMonica I use command export PS1="[\e[;31m][\u@\h \W]\$ [\e[m]". But it does not work.Norway
@DavidRankin-ReinstateMonica Not work. Still show those letters \[\e[1;30m\]\D{}\[\e[1;34m\] \h:\w> \[\e[0m\]export PS1="\[\e[1;30m\]\D{%R}\[\e[1;34m\] \h:\w> \[\e[0m\]" \[\e[1;30m\]\D{}\[\e[1;34m\] \h:\w> \[\e[0m\]Norway
even export PS1="\w" does not work. My terminal cannot interpret it.Norway
Well, did you change your shell to the Catalina default, zsh? Could it be that you're trying to feed a Bash PS1 to zsh? I have no idea how zsh interprets prompt strings, though.Faso
I try [\u@\h:\w]\$ export PS1='\[\e[31m\]\u@\h:\w\[\e[0m\] ' \[\e[31m\]\u@\h:\w\[\e[0m\] which is an example in this link. It still does not work. This is a new mac. I do not whether I should install something or activate PS1.Norway
If you are using zsh, then you will need something like PS1="%F{243}%T %F{27}%m:%~>%f " Post the output of echo $SHELLBrey
Thanks. I don't know the catalina default is zsh instead of bash. I change it to bash.Norway
No problem, had me scratching my head. Thanks @BenjaminW.. See zsh - Prompt Expansion for full documentation on the zsh prompt. Good luck with zsh. I tried for a while, but always came back to bash.Brey
nod. zsh is more forgiving, but that's a double-edged sword; using it, it's easy to get into habits where code you write for any other shell has serious bugs. I swore it off more than 15 years ago now. On the other hand, the version of bash Apple is willing to ship is ancient; installing your own is pretty near mandatory.Evars
BTW, in general, shell prompt questions should be on SuperUser or Unix & Linux; they aren't exclusive to software development, as our rules require. (Mac-only questions can also go to Ask Different).Evars
G
21

I came across this issue as well with a brand new Catalina machine. New models seem to default to zsh shell, instead of the traditional bash, to change this:

Go to Users & Groups (unlock to make admin changes) right-click on your admin user, Advanced Options..., change Login shell to /bin/bash

After right clicking on user

This will allow you to utilize bash's prompt string parsing for a nicer prompt - as mac has traditionally supported in the past.

Gove answered 21/12, 2019 at 20:10 Comment(1)
Even for Monterey this solution worked well.Feel

© 2022 - 2024 — McMap. All rights reserved.