When using read in bash, pressing backspace does not delete the last character entered, but appears to append a backspace to the input buffer. Is there any way I can change
I know the post is old, still this can be useful for someone. If you need specific response to a single keypress on backspace, something like this can do it (without -e):
backspace=$(cat << eof
0000000 005177
0000002
eof
)
read -sn1 hit
[[ $(echo "$hit" | od) = "$backspace" ]] && echo -e "\nDo what you want\n"
The option -n nchars
turns the terminal into raw mode, so your best chance is to rely on readline
(-e) [docs]:
$ read -n10 -e VAR
BTW, nice idea, although I would leave the end of the word to the user (it's a knee-jerk reaction to press return).