shell脚本打印圣诞树


一、脚本文件


#!/bin/bash
#用shell编写一个圣诞树
#创建时间2021-12-21
trap "tput reset; tput cnorm; exit" 2
clear
tput civis
lin=2
col=$(($(tput cols) / 2))
c=$((col-1))
est=$((c-2))
color=0
tput setaf 2; tput bold

# 打印树叶
for ((i=1; i<20; i+=2))
{
    tput cup $lin $col
    for ((j=1; j<=i; j++))
    {
        echo -n *
    }
    let lin++
    let col--
}

tput sgr0; tput setaf 3

# 打印树干
for ((i=1; i<=2; i++))
{
    tput cup $((lin++)) $c
    echo '||'
}
new_year=$(date +'%Y')
let new_year++
tput setaf 1; tput bold
tput cup $lin $((c - 6));  echo   圣 诞 节 快 乐!!!
tput cup $((lin + 1)) $((c - 10)); echo And lots of CODE in $new_year
let c++
k=1

#装饰一下
while true; do
    for ((i=1; i<=35; i++)) {
        # Turn off the lights
        [ $k -gt 1 ] && {
            tput setaf 2; tput bold
            tput cup ${line[$[k-1]$i]} ${column[$[k-1]$i]}; echo *
            unset line[$[k-1]$i]; unset column[$[k-1]$i] 
        }

        li=$((RANDOM % 9 + 3))
        start=$((c-li+2))
        co=$((RANDOM % (li-2) * 2 + 1 + start))
        tput setaf $color; tput bold
        tput cup $li $co
        echo o
        line[$k$i]=$li
        column[$k$i]=$co
        color=$(((color+1)%8))
       
        sh=1
        for l in C O D E
        do
            tput cup $((lin+1)) $((c+sh))
            echo $l
            let sh++
            sleep 0.02
        done
    }
    k=$((k % 2 + 1))
done


二、执行脚本


[root@gzy-centos shell]# chmod +x tree.sh 
[root@gzy-centos shell]# ./tree.sh


三、结果展示




shell脚本打印圣诞树

展开阅读全文

页面更新:2024-04-30

标签:圣诞树   脚本   树干   树叶   文件   时间

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top