栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

保存和还原终端内容

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

保存和还原终端内容

您应该使用 备用屏幕 终端功能。请参见在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#...


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417229.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号