您应该使用 备用屏幕 终端功能。请参见在bash脚本中使用“备用屏幕”]
回答 “如何使用备用屏幕” :
此示例应说明:
#!/bin/sh: <<descShows the top of /etc/passwd on the terminal for 1 second and then restores the terminal to exactly how it wasdesctput smcup #save previous statehead -n$(tput lines) /etc/passwd #get a screenful of linessleep 1tput rmcup #restore previous state
这只能在具有
smcup和
rmcup功能的终端上使用(例如,不能在Linux控制台(=虚拟控制台)上)。可以使用来检查终端功能
infocmp。
在不支持它的终端上,我
tput smcup只需返回退出状态1而不输出转义序列。
注意:
如果打算重定向输出,则可能要直接将转义序列写入到,
/dev/tty以免弄脏
stdout它们:
exec 3>&1 #save old stdoutexec 1>/dev/tty #write directly to terminal by default#...cat /etc/passwd >&3 #write actual intended output to the original stdout#...



