Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    Use double quotes instead of single quotes.

    Code:
    sqlfile=`date +%Y-%m-%d --date="$i days ago"`
    Single quotes prevent variable replacement.

  3. #3
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...