Results 1 to 3 of 3
I have the following code:
for (( i=5; i>=0; i=i-1 ))
do
sqlfile=`date +%Y-%m-%d --date='$i days ago'`
echo $sqlfile
done
How can I get the $i replaced with the contents ...
- 07-27-2009 #1Just Joined!
- Join Date
- Jul 2009
- Location
- Germany
- Posts
- 3
Variable substitution is not working
I have the following code:
for (( i=5; i>=0; i=i-1 ))
do
sqlfile=`date +%Y-%m-%d --date='$i days ago'`
echo $sqlfile
done
How can I get the $i replaced with the contents of $i, everything I try seems to fail
Cheers
John
- 07-27-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Use double quotes instead of single quotes.
Single quotes prevent variable replacement.Code:sqlfile=`date +%Y-%m-%d --date="$i days ago"`
- 07-27-2009 #3Just Joined!
- Join Date
- Jul 2009
- Location
- Germany
- Posts
- 3
Thanks for that.
I just assumed that the single quotes had to be there for the command to work.
It worked with double quotes too.
John


Reply With Quote