临时清除tty

Tom*_*Tom 1 linux bash scripting tty

许多命令(例如watchless)能够暂时清除 tty 以全屏显示信息,然后当命令退出时恢复原始 tty 内容。

有没有办法在 bash 脚本中实现这一目标?

hni*_*cke 5

使用tput。这是一个最小的例子:

#!/bin/bash  
tput smcup    # save the screen
clear         # clear the screen

echo this is some text on a blank screen
echo press any button to exit..
read -n1

tput rmcup    # reset the screen
Run Code Online (Sandbox Code Playgroud)