0

What is wrong with my PS1 ?

export PS1='\[\033[01;34m\]\w \n\[\e[0;32m\$\e[m \]'

When I run it i get the following multi line bash prompt.

~
$

But then If i try to go up in history using "Up Arrow" things go messy for example I can edit parts that shouldn not be editable ie. writing asd in front of "$" is possible.

~
$ echo hiii
hiii

~
$ echo hiii2

~
*asd*$ echo hiii #(By Going back in history using Up Arrow)

Or If I go 5 times or more back with up arrow, than "$" disappears completely like the following

~
echo hii # (This should be "$ echo hii" )
KaO
  • 313
  • 1
  • 3
  • 13
  • 1
    Aside: Don't use `export` when you don't know why you need it. Just `PS1=...` will work fine, with less potential for unwanted side effects. – Charles Duffy Feb 02 '21 at 18:56
  • 1
    ...that said, wrt. the immediate issue, it's caused by the `\[` and `\[` guards being wrong. This is a end-user configuration issue, not a development one, so it's not topical here. – Charles Duffy Feb 02 '21 at 18:57
  • I tried it but got the same exact problems – KaO Feb 02 '21 at 18:58
  • Yes, I know you get the same problems without `export`, but you also get _other_ problems in addition (when `export` is inappropriately used). I can link you to some examples of questions about those other problems if you're curious. – Charles Duffy Feb 02 '21 at 18:58
  • ...here's an example: https://stackoverflow.com/questions/52786257/bash-not-finding-function-when-new-bash-shell-open -- because the `PS1` is exported but the function it depends on is not, child shells have a prompt that requires a function they can't find, so they keep printing "command not found". – Charles Duffy Feb 02 '21 at 19:00
  • Okey, thanks for the info. Do you have any source that can help me to correctly use ```\[``` for fixing my prompt than ? (Related issue also mentions ```\[``` is used worng but not how to use it correctly) – KaO Feb 02 '21 at 19:09
  • 1
    [BashFAQ #53](http://mywiki.wooledge.org/BashFAQ/053) is one of the better sources for walking through the problem and how to fix it. – Charles Duffy Feb 02 '21 at 19:23

0 Answers0