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

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 &

你可能感兴趣的:(在控制台右上角放置一个时钟)