When I use the up-arrow and down-arrow to scroll through the command history, I have a problem with commands longer than 41 characters (the actual character length seems to vary, but that’s irrelevant to the problem). With up-arrow, the typical behavior is to erase the currently displayed command and display the previous command from the history. However, there is a problem with long commands. In such a case, all but the first 16 characters are erased, and the previous command now starts at position 17 after the prompt. If I press to accept the command, it accepts the command starting at position 17, ignoring the preceding text. It is like the first 16 characters of the long command became part of my prompt. If I continue to press up-arrow, the previous commands are shown, starting at position 17, regardless of how long or short the commands are.
FYI, I’m using:
Ubuntu 24.04.2 LTS
Linux 6.8.0-55-generic x86_64
Xfce DE
Gnome Terminal Version 3.52.0
Here’s an example of entering two commands (my prompt is two lines):
[~/computer/test]
[home5-randy]:ls *.tmp
temp.tmp
[~/computer/test]
[home5-randy]:cat 1234567890.tmp
cat: 1234567890.tmp: No such file or directory
[~/computer/test]
[home5-randy]:
Now if I press up-arrow twice, I get:
(up-arrow)
[~/computer/test]
[home5-randy]:cat 1234567890.tmp
(up-arrow)
[~/computer/test]
[home5-randy]:ls *.tmp
everything is as it should be with the previous commands listed in order.
But now I enter the following two commands:
[~/computer/test]
[home5-randy]:ls *.txt
temp.txt test.txt
[~/computer/test]
[home5-randy]:echo “123456789012345678901234567890”
123456789012345678901234567890
[~/computer/test]
[home5-randy]:
and press up-arrow twice:
(up-arrow)
[~/computer/test]
[home5-randy]:echo “123456789012345678901234567890”
(up-arrow)
[~/computer/test]
[home5-randy]:echo "1234567890ls *.txt
You can see that after the first (long) command in the history is displayed, the first 16 characters of that command essentially become appended to my prompt, and the next (previous) command in the history starts at position 17 following my original prompt. In fact, if I press -A to take me to the beginning of the line, it takes me to position 17, the start of the currently displayed command from the history buffer. If I press enter, the command is executed as if the first 16 characters are in fact part of the prompt and not part of the command:
[~/computer/test]
[home5-randy]:echo "1234567890ls *.txt
temp.txt test.txt
This has been an ongoing problem for years, which I would think would be a simple fix that plagues everyone who works in a terminal, but it has not been addressed. I tried changing my prompt to something simple, and that did change the character position but didn’t solve the problem:
[randy][~/computer/test]–:ls *.txt
temp.txt test.txt
[randy][~/computer/test]–:echo “123456789012345678901234567890”
123456789012345678901234567890
(up-arrow)
[randy][~/computer/test]–:echo “123456789012345678901234567890”
(up-arrow)
[randy][~/computer/test]–:echols *.txt
Interestingly, the starting column is 32 for the actual command following a long command for both cases, so it seems as if the prompt is appended to make it exactly 31 characters long.
Okay, I changed my prompt again to make it exactly 31 characters long, and that “solves the problem” in that no additional characters are appended to my prompt.
[randy]1234567[~/computer/test]–:ls *.txt
temp.txt test.txt
[randy]1234567[~/computer/test]–:echo “123456789012345678901234567890”
123456789012345678901234567890
(up-arrow)
[randy]1234567[~/computer/test]–:echo “123456789012345678901234567890”
(up-arrow)
[randy]1234567[~/computer/test]–:ls *.txt
But this is dependent on the length of the prompt, which is variable with the pwd. If I go to the root directory and issue the same commands, I get:
[randy]1234567[~/computer/test]–:cd /
[randy]1234567[/]–:ls .txt
ls: cannot access '.txt’: No such file or directory
[randy]1234567[/]–:echo “123456789012345678901234567890”
123456789012345678901234567890
(up-arrow)
[randy]1234567[/]–:echo “123456789012345678901234567890”
(up-arrow)
[randy]1234567[/]–:echols *.txt
So I could make my prompt even longer, but really, that’s not what I want. I want my prompt to be what I want to set it to and not be appended. Could I reset my prompt after each command to return to my desired state? That would solve the problem, but seems like overkill for what should be an easier fix.
Also, I thought my commands were stored in ~/.bash_history, but that doesn’t seem to be the case. I have a very long history file, but wasn’t able to find my most recent commands. I cleared the file with
/dev/null > ~/.bash_history
and that cleared out the file, but I still have a history I can scroll through. I don’t know where they are stored. Go figure. But that’s a separate issue. Regardless the commands stored in .bash_history looked fine even with extended command lengths beyond 41 characters.
If anyone has a solution to the prompt/history issue, I would appreciate learning of it. Thank you.