Operating System - HP-UX
1753442 Members
4709 Online
108794 Solutions
New Discussion юеВ

date "n" date ago change with variable

 
dikiery
New Member

date "n" date ago change with variable

Hi All,
I want to write a script to get a date 5 days ago from current date or after from current date.

perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time-(5*60*60*24))'

i know with the scirpt it's work

but my problem is change the 5 value with a variablem??


$ perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time-(5*60*60*24))'
2009-02-22
$ n=5
$ echo $n
5
$ perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time-($n*60*60*24))'
2009-02-27




help me

thanks
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: date "n" date ago change with variable

The shell won't replace $n if in single quotes. So you can use "" instead (and quote each embedded double quote) or stutter the quotes:
perl -MPOSIX -le 'print strftime "%Y-%m-%d",localtime(time-('$n'*60*60*24))'
dikiery
New Member

Re: date "n" date ago change with variable

@Dennis Handly

thank you very much
:D
Dennis Handly
Acclaimed Contributor

Re: date "n" date ago change with variable

>thank you very much

If you are happy with the answers you have gotten, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
dikiery
New Member

Re: date "n" date ago change with variable

thanks for you'r help