Using eval works, but is bad practice for security reasons. The Right Thing, when you need to perform redirections inside code stored for reuse, is to define a function:
cmd() { some_command &> output.log; } # define it
declare -p cmd # print it
cmd # run it
If you don't need redirections, then the right thing is an array:
cmd=( something 'with spaces' 'in args' ) # define it
printf '%q ' "${cmd[@]}"; echo # print it
"${cmd[@]}" # run it
This is safer, inasmuch as array contents won't go through a full eval pass. Think about if you did cmd="something-with $filename", and filename contained $(rm -rf /). If you used eval, this would run the rm command!
To provide a more specific example, this would hose your system if run as root:
# !!! I AM DANGEROUS DO NOT RUN ME !!!
evil_filename='/tmp/foo $(rm -rf /)'
cmd="echo $evil_filename" # define it (BROKEN!)
eval "$cmd" # run it (DANGEROUS!)
On the other hand, this would be safe:
evil_filename='/tmp/foo $(rm -rf /)'
cmd=( echo "$evil_filename" ) # define it (OK!)
printf '%q ' "${cmd[@]}"; echo # print it (OK!)
"${cmd[@]}" # run it (OK!)
...and it would still be safe even if you left out some of the quotes -- it would work wrong, but still not break your system:
# I'm broken, but not in a way that damages system security
evil_filename='/tmp/foo $(rm -rf /)'
cmd=( echo $evil_filename ) # define it (BROKEN!)
${cmd[@]} # run it (BROKEN!)
And this would be safe too:
evil_filename='/tmp/foo $(rm -rf /)'
cmd() { echo "$1"; } # define it (OK!)
cmd "$evil_filename" # run it (OK!)
For a more in-depth discussion, see BashFAQ #50 (on properly storing command sequences for reuse), and BashFAQ #48 (on why eval is dangerous).
.in your second code example is not treated as a concatenator, which seems to be what you expect (I guess you're probably coming from Perl or something?); instead, it's printed literally. Just remove it. (Also, as devnull pointed out, you need to remove the spaces around=.)echo one two threeis the same asecho "one two three"orecho one two three, butecho "one two three"is different because the quotation marks will cause the spaces to be preserved.