1

I have MacOS and .bash_profile content:

export PS1="\[\e[0;31m$\]\[\e[m\] \[\e[0;32m\w\e[m\] : \]"

as a result I have pwd printed in terminal like this:

Screen capture

but when I press up and down arrows to use terminal history I have bug:

enter image description here

8
  1. no need to export PS1: it's a variable for the shell, other processes aren't going to use it.
  2. looks like you don't have the escaping brackets quite right. They are there to surround non-printing sequences, so bash can accurately figure how wide your prompt is. Try this:

    PS1="\[\e[0;31m\]\$ \[\e[0;32m\]\w\[\e[0m\] : "
    #     1.........1    2.........2   3......3 
    

    So the printing bits (\$, \w, the colon and the spaces) are outside the brackets.

Further reference: https://www.gnu.org/software/bash/manual/bashref.html#Controlling-the-Prompt

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.