I'm running into a problem with a differential backup script written in GNU Bash 3.0 - the following stripped down code demonstrates the problem quite nicely.
$ DATE="last tuesday"
$ date --date="$DATE"
Tue Jan 6 00:00:00 PST 2009
So far so good.
$ CMD="date --date=\"$DATE\""
$ echo $CMD
date --date="last tuesday"
$ $CMD
date: the argument `tuesday"' lacks a leading `+';
When using an option to specify date(s), any non-option
argument must be a format string beginning with `+'.
Try `date --help' for more information.
How can I wrap these variables up correctly? It seems like it's not parsing the quotes correctly, but from the contents of the CMD variable (see above), it looks fine. What gives?
$ DATE="last tuesday"
$ CMD="date --date=\"+$DATE\""
$ $CMD
date: the argument `tuesday"' lacks a leading `+';
When using an option to specify date(s), any non-option
argument must be a format string beginning with `+'.
Try `date --help' for more information.
That just runs "date" immediately and sticks the output into the variable CMD. I want to be able to craft a longer command out of several variables, and then run it multiple times.