美文网首页运维小技巧程序员
在控制台右上角放置一个时钟

在控制台右上角放置一个时钟

作者: haw_haw | 来源:发表于2017-03-20 15:14 被阅读64次

tput 版本

while sleep 1
do
  tput sc
  tput cup 0 $(($(tput cols)-29))
  date
  tput rc
done &

解释下:

  • tput sc # 记录下当前光标位置
  • tput cup 0 ..... # 这一句是更改光标到最上一行右起第 29 位置
  • date # 是打印下当前时间(28 个字符)
  • tput rc # 是恢复先前保留的光标位置

escape codes 版本

while true
do
  echo -ne "\e[s\e[0;$((COLUMNS-27))H$(date)\e[u"
  sleep 1
done &

相关文章

网友评论

    本文标题:在控制台右上角放置一个时钟

    本文链接:https://www.haomeiwen.com/subject/bqxinttx.html