First, create test files test.sh
#!/bin/sh
./etc/profile
# Parameters:
# Args[0], data date, date format Yyyy-mm-dd
# Take 30 days before the date
function Get_date_ 30daysbefore ()
{
sec= ' date-d $ +%s '
sec_30daysbefore=$ ((sec-86400*30))
days_before= ' date-d @$ Sec_30daysbefore +%f '
echo $days _before
}
If [$# = 1]; then today=$1 dates_30=
' Get_date_ 30daysbefore '
else
today= ' date-d -1days ' +%y-%m-%d ' dates_30= ' date-d
-30days
' +%y-%m-%d ' Fi
echo $today
echo $dates _30
Ii. Non-parametric operation
# # without parameters, starting from the current time
$./test.sh
2016-10-28
2016-09-29
Third, the transfer of the parameters of the operation
$./test.sh 2015-10-29
2015-10-29
2015-09-29
Summarize
The above is the use of shell to get the specified date of the date of the full content of N days, I hope the content of this article for everyone's study or work can help, if there is doubt you can message exchange.