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