婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > shell打印給定日期的日歷

shell打印給定日期的日歷

熱門標簽:輝縣市地圖標注 地圖標注x是啥意思 外呼系統(tǒng)的合法性 房產(chǎn)證地圖標注的兩個面積 威海電銷外呼系統(tǒng)好用嗎 湖北孝感如何辦理 同花順電話機器人微信 武漢語音電銷機器人加盟 北京電銷機器人對市場的影響

學習shell有一段時間了,一直沒有機會練手,看到同事發(fā)了一張照片,控制臺顯示了當月的日歷,是用Python實現(xiàn)的,感覺挺好玩,所以準備用shell來實現(xiàn)一個,搞了一下午,終于搞定。

打印本月的日期

#! /bin/bash
#設置字體顏色
tiffcolor="\033[0;35m"
menucolor="\033[0;33m"
todaycolor="\033[0;35;44m"
start="\033[0m"

#計算各個日期
month=`date +%m`
day=`date +%d`
year=`date +%Y`
weekday=`date -d "$year-$month-01" +%w`
nextmonth=`expr $month + 1`
today=`date +%d`
#計算本月有多少天
differ=$(( ($(date -d "$year-$nextmonth-01" +%s) - $(date +%s))/(24*60*60) )) 
days=`expr $differ + $day`

#打印標題
echo -en "${menucolor}"
echo -en "\t  $year $month\n"
echo "SUN MON TUE WEN THU FRI SAT"
echo -en "${start}"

#打印空格
if [ $weekday -ne 0 ];then
for((i=1;i=$weekday;i++))
do
  echo -n "  "
  echo -n " "
done
fi

#打印日期
for((i=1;i=$days;i++))
do
  printf "%s" " "
  echo -en "${tiffcolor}"
  #今天高亮顯示
    if [ $today -eq $i ];then
      echo -en "${todaycolor}"
    fi
  printf "%2d" $i
  echo -en "${start}"
  echo -en " "
  if [ $((($weekday+$i)%7)) == 0 ];then
    echo ""
  fi
#  printf "%3d " $i
done
echo ""

執(zhí)行結果:

擴展:給定任意日期,打印當月的日期

#! /bin/bash
#date=$1
tiffcolor="\033[0;35m"
menucolor="\033[0;33m"
todaycolor="\033[0;35;44m"
start="\033[0m"


if [ $# -ne 1 ];then
  echo "plz input the date"
  exit 1
fi
date=$1
count=`echo $date |grep -o '-'|wc -l`
if [ $count -ne 2 ];then
  echo "plz input correct date"
  exit 1
fi
year=`echo $date|cut -d "-" -f 1`
month=`echo $date|cut -d "-" -f 2`
day=`echo $date|cut -d "-" -f 3`
expr $year + $month + $day + 0 >/dev/null
if [ $? -ne 0 ];then
  echo "plz input a correct date"
  exit 1
elif [ $month -gt 12 -o $month -eq 0 ];then
  echo "plz input the month between 1 and 12"
  exit 1
elif [ $day -gt 31 -o $day -eq 0 ];then
  echo "plz input the day between 1 and 31"
  exit 1
fi

#nextmonth=$(( $month + 1))
#month=`date -d "$date" +%m`
#day=`date -d "$date" +%d`
#year=`date -d "$date" +%Y`
weekday=`date -d "$year-$month-01" +%w`
if [ $month -eq 12 ];then
  newmonth=1
  newyear=`expr $year + 1`
else
  newyear=$year
  #nextmonth= expr $month + 1
  newmonth=`expr $month + 1`
fi
days=$(( ($(date -d "${newyear}-${newmonth}-01" +%s) - $(date -d "$year-$month-01" +%s))/(24*60*60) )) 
#echo $days
echo -en "${menucolor}"
echo -en "\t  $year $month\n"
echo "SUN MON TUE WEN THU FRI SAT"
echo -en "${start}"

if [ $weekday -ne 0 ];then
for((i=1;i=$weekday;i++))
do
  echo -n "  "
  echo -n " "
done
fi


for((i=1;i=$days;i++))
do
  printf "%s" " "
  echo -en "${tiffcolor}"
    if [ $day -eq $i ];then
      echo -en "${todaycolor}"
    fi
  printf "%2d" $i
  echo -en "${start}"
  echo -en " "
  if [ $((($weekday+$i)%7)) == 0 ];then
    echo ""
  fi
#  printf "%3d " $i
done
echo ""

執(zhí)行結果:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • shell腳本實現(xiàn)日歷的屏幕控制
  • 使用AWK在shell中生成日歷小程序

標簽:武威 日喀則 安康 迪慶 紹興 西寧 麗江 蚌埠

巨人網(wǎng)絡通訊聲明:本文標題《shell打印給定日期的日歷》,本文關鍵詞  shell,打印,給定,日期,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《shell打印給定日期的日歷》相關的同類信息!
  • 本頁收集關于shell打印給定日期的日歷的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 伊宁县| 嘉定区| 兰考县| 石屏县| 黔南| 百色市| 东阳市| 郴州市| 黔东| 高清| 水城县| 内乡县| 寿光市| 大名县| 永平县| 法库县| 六枝特区| 沂南县| 辉县市| 福贡县| 噶尔县| 周宁县| 孟津县| 玉树县| 酒泉市| 南木林县| 巴南区| 日喀则市| 绵阳市| 当涂县| 兰州市| 遂昌县| 西丰县| 团风县| 深州市| 辽中县| 黄冈市| 宝应县| 宜兰市| 横山县| 门头沟区|