3

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?

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
smarber
  • 4,829
  • 7
  • 37
  • 78

2 Answers2

4

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.

evil otto
  • 10,348
  • 25
  • 38
0

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).

piokuc
  • 25,594
  • 11
  • 72
  • 102