[PLUG] bash question
Roderick A. Anderson
raanders at acm.org
Mon Aug 19 18:23:46 UTC 2002
On Mon, 19 Aug 2002, Marvin J. Kosmal wrote:
> On Monday 19 August 2002 10:46, you wrote:
> > I'm writing a script where I want to figure out what month it will
> > be X weeks from today. If it were one week from today, I could use
> > date like this:
> >
> > date --date='+ 1 week' +%m
> >
> > This stores it to a variable (X):
> >
> > X=$(date --date='+ 1 week' +%m)
> >
> > But what if the 1 in the above statement is itself a variable?
> >
> > Y=1
> > X=$(date --date='+ $Y week' +%m)
> >
> > I get this error:
> >
> > date: invalid date `+ $Y week'
> >
> > How do I proceed here?
>
>
> Try $(Y) week
Or double quotes. Single quotes (apostrophes) hide/prevent variable
expansion.
X=$(date --date="+ $Y week" +%m)
Btw, I had a similar need coming up and hadn't thought too much about how
to s similar 'calculation'. Thanks!
Rod
--
"Open Source Software - Sometimes you get more than you paid for..."
More information about the PLUG
mailing list