首页 > 解决方案 > 临时清除 tty

问题描述

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

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

标签: linuxbashscriptingtty

解决方案


使用 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

推荐阅读