Hi I am using Fedora 37 and came across next problem.
Adding
export PS1="\e[43;39m[\t]\w\r\n[\u@\h]\\$\e[40m \[$(tput sgr0)\]"
to my .bashrc
file in /home/username
in my case led up to this unexpected behaviour. As I start typing bash commands and fill the whole line the characters don't go to the next line but just continue to get outprinted in the same line overriding the content at the begging of the line. As example: 1
I'm not really familiar with bash syntax so I would appreciate help from a fellow expert.
1 Answer
As pynexj indicated, you need braces. However, the tput is probably nullifying more than you expect. You should keep it simple with the basic escape sequence.
Also you have "[40m" in your original string. I believe that was a mistype and should be "[0m", which is the sequence for "reset attributes".
Try using this instead:
export PS1="\[\e[43;39m\][\t]\w\r\n[\u@\h]\\$\[\e[0m\]"
Also, I would personally use ";30m" instead of ";39m". The corresponding definition would be:
export PS1="\[\e[43;30m\][\t]\w\r\n[\u@\h]\\$\[\e[0m\]"
For comparison, on Ubuntu MATE 20.04, the .bashrc definition is:
export PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
Since I experienced the same problem using your original string, I can explain what happened.
As you let the input buffer fill, it wrapped-around early, before reaching the terminal width, and this for the distance equivalent to the count of characters that were not properly "framed" by the square brackets. Not being framed properly, while not visible, they were counted as part of the linewidth for line buffer character count, so it did a "carriage return" to column one, overwriting what was there. Because of that, the curses logic didn't encounter the "line end" condition, so it did not kick in for the expected linefeed.
-
Thank you, I tried your solution and it works. Thank you also for the explanation, it was helpful.– GabrijelOkornCommented Dec 6, 2022 at 22:09
\e[43;39m
also need to be enclosed in\[ ... \]
.\e[43;39m\]
\[\e43;39m\]