I read multiple answers with varying complexities. Most are working well when the input is typed manually.
For example: https://stackoverflow.com/a/20913871/1841533 .
Here is my sample code, very close to the one in that answer:
_delay_end_input_=2 printf "%s\n" "answer: " IFS= read -d '' -n 1 theanswer while IFS= read -d '' -n 1 -t ${_delay_end_input_} more ; do theanswer="${theanswer}${more}" done This also works great when I type the answer manually, ie: character by character...
But if I paste a line (or several) : it echoes the "remaining buffer" after each character is read... making a mess of the display.
I haven't yet found a way to hide this, while keeping the normal echoing on screen. (ie, if typing or pasting, I still want to see what is typed/pasted)
Short example: Here is the (good) prompt while I type manually "abcd", character by character:
answer: abcd But if I supply "abcd" by pasting it in a single moment with the mouse, it messes up the echoing by repeating after each character is read the remaining entire buffer:
answer: abcdbcdcdd tl/dr: the snippet works great when entering character by character, but echoes remaining reading buffer after reading each char of a pasted entry.