I try to use read command to catch what user enters.
read -p "Please enter your name -> " -n 20 name
But I figured out that we can't rectify what we have entered. How can I make the "BackSpace" remove and not add?
I try to use read command to catch what user enters.
read -p "Please enter your name -> " -n 20 name
But I figured out that we can't rectify what we have entered. How can I make the "BackSpace" remove and not add?
The easiest way is to use the -e
flag to read, which will make it use readline.
read -e -p "Please enter your name -> " -n 20 name
You could also change your terminal settings (stty) so that backspace instead of delete is erase.
You can pipe the text entered by the user (or any other text) through col -b
, for example:
name=`echo $name|col -b`
This is more portable than using option -e
of the read
command, because -e
is not supported on all Unix systems, for example AIX (I think it is a GNU/Linux extension).