Search code examples
linuxbashshellubuntutput

backspace does not remove tput command's underline in bash


i'm trying to practice to do a nice and neat interface. However, i'm stuck at this problem. I'm trying to underline the input of the user which i managed to do it using this method

echo -n "Title : "; read -p "$(tput smul)" getTitle; tput rmul 

tput smul is used to underline the word while tput rmul is used to remove the underline after this statement is successful.

Unfortunately, when i accidentally typed wrongly and decided to back space, the underline did not disappear accordingly.

Instead, the underline remains there even though i removed all the user input.

Is there any solution for this?


Solution

  • Use readline via the -e flag:

    echo -n "Title : "; read -ep "$(tput smul)" getTitle; tput rmul