linux shell实现动态时钟

最近再看有关linux shell方面的东西,偶尔看到说在终端上实现动态时钟,就在网上搜了一下

http://blog.csdn.net/reage11/article/details/8586200  这个博客写的可以 容易懂,但我再仔细看他的代码时,发现不需要用switch来判断月份,Linux命令的伟大之处已经超出了我们的想象,因此,我将代码修改如下:

#!/bin/bash
tput civis
while [ 1 ]
do
   tput clear
   tput cup 3 10
   tput setb 0
   tput setf 2
   echo $(date "+%Y--%m--%d %H:%M:%S  %A")
   sleep 1

done

原文如下:

    #!/bin/bash    
    tput civis  
    while [ 1 ]  
    do  
        nonth=$(date +%B)  
        case "$nonth" in  
            January)  nonth=1;;  
            February)  nonth=2;;  
            March)  nonth=3;;  
            April)  nonth=4;;  
            May)  nonth=5;;  
            June)  nonth=6;;  
            July)  nonth=7;;  
            August)  nonth=8;;  
            September)  nonth=9;;  
            October)  nonth=10;;  
            November)  nonth=11;;  
            December)  nonth=12;;  
        esac  
            tput clear  
            tput cup 3 10  
        echo $(date +%Y)--$nonth--$(date +%d) $(date +%H):$(date +%M):$(date +%S) $(date +%A)  
        sleep 1  
           
    done  

相关知识(从上面链接拷过来的):

tput命令参数介绍:

     tput civis :用来隐藏光标

     tput cols :显示当前所在的列

     tput lines :显示当前所在的行

     tput cup lines cols : 将光标移动到第lines行,第cols列

     tput setb no :设置终端背景色。 no的取值稍后介绍

     tput setf no : 设置文本的颜色。no的取值稍后介绍

     tput ed :删除当前光标到行尾的内容

     no的取值:0:黑色、1:蓝色、2:绿色、3:青色、4:红色、5:洋红色、6:黄色、7:白色

     更多内容请使用 man tput 查看

date命令参数介绍

    

         %H :小时(0..23)%I : 小时(01..12)
         %M : 分钟(0..59)
          %p : 显示本地时段“上午”或 “下午”
         %r : 直接显示时间 (12 小时制,格式为 hh:mm:ss [AP]M)
         %s : 从 1970 年 1 月 1 日 00:00:00 UTC 到目前为止的秒数
         %S : 秒(00..61)
         %X : 相当于 %H:%M:%S
         %a : 星期几 (Mon..Sun)         %A : 星期几 (Monday..Sunday)
         %b : 月份 (Jan..Dec)              %B : 月份 (January..December)
         %c : 直接显示日期与时间
         %d : 日 (01..31)                   %D : 直接显示日期 (mm/dd/yy)
         %j : 一年中的第几天 (001..366)
         %m : 月份 (01..12)
         %x : 直接显示日期 (mm/dd/yy)
         %y : 年份的最后两位数字 (00.99)         %Y : 完整年份 (0000..9999)

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值