There is a strange behavior in all or most Linux terminal, which has bugged me for a long time. I am not sure if it is a bug or intended, or a configuration issue. So I ask here first.
Steps to reproduce
- Open a terminal.
- Optional: Run
export PS1='~ \$'
, to standardize this setting. Feel free to play around with this setting. - Run
echo -n hello
. - Use "Up" key to get the previous command.
- Use "Down" arrow key to get back to the empty prompt.
- Use "Up" again.
Expected
(this is with my own $PS1 that leaves ~ $
.)
After running echo -n hello
:
~ $ echo -n hello
hello~ $
After "Up" arrow key:
~ $ echo -n hello
hello~ $ echo -n hello
After "Down" arrow key:
~ $ echo -n hello
hello~ $
After second "Up" arrow key:
~ $ echo -n hello
hello~ $ echo -n hello
Actual
(this is with my own $PS1 that leaves ~ $
.)
(first two steps as in "Expected")
After "Down" arrow key:
~ $ echo -n hello
hell
After second "Up" arrow key:
~ $ echo -n hello
hellecho -n hello
Variations
- Use different values of $PS1.
- Use strings of different lengths in echo.
- Go further back in the history. For me, some history values have a different effect than others.
My terminal
I am using
Konsole Version 21.12.3
But I think I saw this also in other terminals in the past. I don't know if KDE "Konsole" is responsible for this behavior.
Additional information
(in response to comments below)
It does not happen for user "root"!
Initially I saw a difference between my own user and user root
. But it turned out this was only due to differences in the $PS1
setting. After normalizing this value to '~ \$'
, or '${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\w\[\033[00m\] \$ '
, I now see same behavior for root and myself.
It also happens in bash inside a docker container which has a completely independent setup.
Links
For the record, I opened an issue here, https://bugs.kde.org/show_bug.cgi?id=464384
sh
ordash
should be available). What shell are you using?^[[A
and^[[B
.echo $TERM
->xterm-256color
. Now I am not sure what to look for and what to change.