Shell script Case--Gets the date of the day before the current date

Source: Internet
Author: User
Tags function definition

Record a shell script case that includes some syntax for the shell (function definition, expression operation, if, case ...). )

#!/bin/sh

#获取当前时间
run_time= ' Date +%h%m%s '
#取当前日期前一天
Get_ydate ()
{
#设置当前年月日
today= ' Date +%y%m%d '
Month= ' Date +%m '
day= ' Date +%d '
Year= ' Date +%y '
#字符转换称数字
Month= ' expr $month + 0 '
#取前一天
day= ' expr $day-1 '

#如果前一天为0, perform the following processing
If [$day-eq 0]; Then
#取前一月月份.
Month= ' Expr $month-1 '
#如果前一月为0, the month of the previous year, the 12th month
If [$month-eq 0];then
Month=12
Day=31
Year= ' Expr$year-1 '
#如果前一月份不为零, the day of the month is judged by the month
Else
Case $month in
1|3|5|7|8| 10|12) day=31;;
4|6|9|11) day=30;;
2)
if [' Expr $year% 4 '-eq 0]; Then
If [' Expr $year% '-eq 0]; Then
day=29
elif [' Expr $year% '-eq 0]; Then
Day=28
Else
day=29
Fi
Else
Day=28
fi
;;
Esac
Fi
Fi
#按照YYYYMMDD格式打印年日期
acct_date= ' printf "%04d%02d%02d" "$year" "$month" "$day"
Echo $RUN _time
Echo $acct _date
}
Get_ydate

Shell script Case--Gets the date of the day before the current date

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.