How to write a shell script where to add days month and year to the current date

I am new to shell script.

I want to write a script where I add days month and years to the current day. for example, it takes the current date and every time addd 3 is on day 4 to months and from 2 to years. all three things are given as arguments.

I would be very grateful.

Vg

+5
source share
3 answers

Tip: run a terminal (in my case, a bash terminal)

help is a good starting point

date --help

or man page

man date

A lot of information and examples.

Processing data in bash (copy the example that runs in your terminal):

add 10 days to the current date:

date -d "10 day" +"%Y %m %d"

or delete 10 days before the current date

date -d "-10 day" +"%Y %m %d"

add 2 months to the current date:

date -d "2 month" +"%Y %m %d"

remove 2 months from the current date:

date -d "-2 month" +"%Y %m %d"

1

date -d "1 year" +"%Y %m %d"

1

date -d "-1 year" +"%Y %m %d"

1

date -d "1 year 1 month 1 day" +"%Y %m %d"

script ( bash)

foobaa=`date -d "1 year 1 month 1 day" +"%Y %m %d"`
echo $foobaa

, .

+10

Mac OSX - -v "+ 60M", 60 .

+1

A simple short command
date -d "+3 days +4 months +2 years"

In the same way, you can also subtract dates.
date -d "-3 days -4 Month -2 Years"

0
source

All Articles