sunknudsen
sunknudsen

Reputation: 7310

How to clear read input when using tput rc?

$ cat test.sh
#!/bin/bash

sc=$(tput sc)
rc=$(tput rc)

printf "$sc%s\n" "Type word"
read -r word
printf "$rc%s\n" "Type word (again)"
read -r word_confirmation

$ ./test.sh
Type word (again)
test

I would like test to be cleared.

Upvotes: 2

Views: 828

Answers (1)

DerMaddi
DerMaddi

Reputation: 729

tput ed clears the screen from the current cursor position to the end of the screen (broken on macOS, see this answer).

#!/bin/bash

tput sc
printf "%s\n" "Type word"
read -r word
tput rc
tput ed
printf "%s\n" "Type word (again)"
read -r word_confirmation

tput clear screen

Upvotes: 5

Related Questions