开发者社区> 问答> 正文

《命令行下做时钟》中奖代码展示(3) —— Shell篇

双11的时候,@阿里云安全 做了一个小活动,想看看有多少人能在命令行下搞出时钟效果,用现成的程序或自己编程都ok。


前面已经放出了高级开发工具实现的一批(涵盖Linux/Windows平台),这里再放出Shell实现的一批。


作者:@__MartinWu @rustico @OwenChia


方式:tmux下Ctrl b, t


环境:CentOS 7/RHEL 6 /Ubuntu 14下调试通过


效果:





*******************************************************************

作者:@wbingeek @被吊打的redrain @幸福的酸梅汤 @小八没在家 @爱喝白琳的Gina @爱吃青菜的呼呼呼 @大憨0xCD21 @XuYuanzhen

方式:Shell编程


环境:Fedora 20/RHEL 5/Ubuntu 14


效果:





效果:






效果:





效果:





效果:








代码:

tty-clock -c -f " " -C 4 [font=Arial, 'Microsoft YaHei']



代码:


watch -t -n1 "date +%T|figlet -W -f big"


代码:

clear;
while true;
do tput cup 10 10;
echo `date +%T`;
sleep 1;
clear;
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

代码:

#!/bin/bash
TIME=`date "+%H:%M"`
char="0"
bg="\x1B[0;37;40m"
fg="\x1B[0;37;42m"
HOR=10
VER=9
clock()
{
TIME=`date "+%H:%M"`
}
plot()
{
p="\x1B["$VER";"$HOR"f"
VER=$[ ( $VER + 1 ) ]
}
zero()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$fg $bg  $fg  $bg "
plot
printf "$p$fg $bg $fg $bg $fg $bg "
plot
printf "$p$fg  $bg  $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
one()
{
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg  $fg  $bg  "
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg  $fg   $bg "
}
two()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg     $bg "
}
three()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
four()
{
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg  $fg  $bg  "
plot
printf "$p$bg $fg $bg $fg $bg  "
plot
printf "$p$fg $bg  $fg $bg  "
plot
printf "$p$fg     $bg "
plot
printf "$p$bg   $fg $bg "
plot
printf "$p$bg   $fg $bg "
}
five()
{
plot
printf "$p$fg     $bg "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg $bg     "
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
six()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg    $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
seven()
{
plot
printf "$p$fg     $bg "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$bg   $fg $bg  "
plot
printf "$p$bg  $fg $bg   "
plot
printf "$p$bg $fg $bg    "
plot
printf "$p$fg $bg     "
plot
printf "$p$fg $bg     "
}
eight()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
nine()
{
plot
printf "$p$bg $fg   $bg  "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$fg $bg   $fg $bg "
plot
printf "$p$bg $fg    $bg "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$bg    $fg $bg "
plot
printf "$p$bg $fg   $bg  "
}
colon()
{
plot
printf "$p$bg      "
plot
printf "$p$bg      "
plot
printf "$p$bg  $fg $bg   "
plot
printf "$p$bg      "
plot
printf "$p$bg  $fg $bg   "
plot
printf "$p$bg      "
plot
printf "$p$bg      "
}
clear
while true
do
clock
for subscript in $( seq 0 1 4)
do
char="${TIME:${subscript}:1}"
HOR=$[ ( 26 + ( $subscript * 6 ) ) ]
VER=9
if [ "$char" == ":" ]
then
colon
fi
if [ "$char" == "0" ]
then
zero
fi
if [ "$char" == "1" ]
then
one
fi
if [ "$char" == "2" ]
then
two
fi
if [ "$char" == "3" ]
then
three
fi
if [ "$char" == "4" ]
then
four
fi
if [ "$char" == "5" ]
then
five
fi
if [ "$char" == "6" ]
then
six
fi
if [ "$char" == "7" ]
then
seven
fi
if [ "$char" == "8" ]
then
eight
fi
if [ "$char" == "9" ]
then
nine
fi
done
sleep 1
done


**********************************************************************
(以上代码和效果已分开摆放,需要测试的同学请勿按顺序对照,以最终效果为准。)


展开
收起
虎笑 2014-11-17 10:59:09 11777 0
2 条回答
写回答
取消 提交回答
  • 高端大气上档次,可惜不能泡妹子!

    -------------------------

    高端大气上档次,可惜不能泡妹子!

    2014-11-18 16:18:03
    赞同 展开评论 打赏
  • Re《命令行下做时钟》中奖代码展示3——Shell篇
    小白过来膜拜的。。。
    2014-11-17 13:37:45
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Shell 脚本速查手册 立即下载
小程序 大世界 立即下载
《15分钟打造你自己的小程序》 立即下载