1

On my mac and Ubuntu I have my PS1 values set to the below:

export PS1='\[\e[1;31m\]\d\[\e[0m\] \[\e[1;32m\]\u  \W\[\e[0m\] \[\e[1;36m\]>\[\e[0,\] \[$(tput sgr0)\]'

On Ubuntu the terminal prompt looks fine. But on my Mac an extra "B" is placed, like below:

Mon Jan 16 DrizzutoJr  ~ >B

I am assuming Mac and Ubuntu handle the value slightly differently. Can someone explain what's going on and how to fix it?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
  • Are you using `bash` or some other shell? I can not reproduce this with the stock `bash` on macOS (3.2.57(1)-release), nor with a later `bash` release (4.4.5(1)-release). – Kusalananda Jan 16 '17 at 08:29

1 Answers1

1

That \[\e[0,\] is suspect, since the enclosed text escape, does not correspond to a valid "ANSI" escape sequence (the comma is not a valid final byte). It may happen to "work" with VTE (which has a lot of interesting cut/paste in its innards), but on other terminals, you're likely to get a stray character which will show up.

Perhaps you intended an adjacent key on the keyboard, m.

By the way, $(tput sgr0) is likely to produce the equivalent of \e[0m as well (using tput consistently throughout the expression would work as well, and though more verbose, perhaps more readable).

Further reading:

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • I was just about to give Kusalananda a hint, too. (-: See http://apple.stackexchange.com/questions/256449/ for the sort of advice that is being bandied about in Apple Land. – JdeBP Jan 16 '17 at 09:29
  • Thank you, that was correct. Very helpful. Can you just spell out what VTE is? – user3299745 Jan 16 '17 at 09:51
  • [VTE is the actual terminal emulator](https://git.gnome.org//browse/vte/) for the various "skins" known as gnome-terminal, xfce-terminal, etc. – Thomas Dickey Jan 16 '17 at 10:00