First of all, aw two things to make clear:
- Yes I've seen there are already several questions with a similar sounding headline, but they are neither talking about the same situation nor do they have a satisfactory answer.
- When I mean "bash prompt" I'm not talking about the prompt my terminal/shell gives me, but a
readprompt inside an interactive script. I don't experience this issue only inside a script, not in the "normal" shell prompt (in my case: macOS Terminal Application, Bash 5.0).
That being said, I have user prompt inside my script. Let's say, it looks like the following:
read -rp "Enter your name: " name
So far, so good. As long as the user doesn't make a spelling mistake this probably works without any issues. Yet, when the user wants to correct something they better not use the arrow keys. If they do, contrary to their expectations, the curser won't move, but weird characters appear:
Enter your name: Sanantha^[[D
Is there a way to avoid these - what I've learned from the other threads - ANSI codes from appearing? The expected behavior would be to actually move the curser to the left by one character, each time the "left" key is pressed.
As this is a script to be distributed, it would be best, if this can be fixed inside the script and doesn't require messing with config files.
Kind regards!