【问题标题】:How to clear read input when using tput rc?使用 tput rc 时如何清除读取输入?
【发布时间】:2021-02-26 02:38:34
【问题描述】:
$ 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

【问题讨论】:

    标签: bash tput


    【解决方案1】:

    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

    【讨论】:

    • 您好,感谢您的帮助。上面的代码似乎不起作用......整个屏幕都被清除了......不仅仅是test。你介意调整你的代码块来扩展我的代码吗?
    • 显然,macOS 上有一个bug 破坏了tput ed
    • 您使用 macOS 并且 tput cd 在您的机器上工作吗?顺便说一句,我对printf '%q' "$(tput ed)" 的输出是$'\E[J'
    • 我在 macOS 上开发了一个脚本。 printf '%q' "$(tput ed)" 在 macOS Catalina 上输出 ''printf '%q' "$(tput cd)" 输出 $'\033'\[J.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    相关资源
    最近更新 更多