0
$ 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被清除。

4

1 回答 1

3

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

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

于 2021-02-25T17:27:31.660 回答