使用 tput rc 时如何清除读取输入?

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

我想test清零

tput ed 从当前光标位置到屏幕末尾清除屏幕(在 macOS 上损坏,请参阅 this 答案)。

#!/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