Build git log statement using bash script, throws ambiguous argument '%an' error
<p>I want to construct and execute the following git log statement to get summary of commits for yesterday for specific authors: <code>name1</code> and <code>name2</code>, so the final desired executed git log should be as follows:</p>

<pre><code>git log --author name1 --author name2 
        --since yesterday --reverse
        --pretty=format:"%h - %an , %ad : %s" &gt; commits.txt
</code></pre>

<p>As you may notice output is redirected to <code>commits.txt</code> file. </p>

<p>The output <code>commits.txt</code> file should finally contain some text like this:</p>

<pre><code>350411e - name1, Mon Apr 18 18:03:01 2016 +0200 : Fix bug X
366411e - name2, Mon Apr 18 18:05:06 2016 +0200 : Introduce feature Y
752411e - name1, Mon Apr 18 18:11:12 2016 +0200 : Merge version Z
</code></pre>

<p>Here's my code in <code>script.sh</code></p>

<pre><code>team=( name1 name2 )

function create_commits_log_file () {
    authors=''
    for author in "${@}"
    do
        authors="$authors --author $author "
    done
    git_log_statement="git log $authors --since yesterday --reverse --pretty=format:\"%h - %an , %ad : %s\" &gt; commits.txt"
    echo "$git_log_statement"
    $git_log_statement
}

create_commits_log_file "${team[@]}"
</code></pre>

<p>Unfortunately when I run it as <code>bash script.sh</code>, it throws an error:</p>

<blockquote>
  <p>git log  --author name1  --author name2  --since yesterday --reverse
  --pretty=format:"%h - %an , %ad : %s" > commits.txt</p>
  
  <p>fatal: ambiguous argument '%an': unknown revision or path not in the
  working tree.</p>
  
  <p>Use '--' to separate paths from revisions, like this: 'git 
  [...] -- [...]'</p>
</blockquote>

<p>Despite that if I run the <code>echo</code>'ed git command on console it works perfectly!</p>

<p>What is the problem ? and how may I fix it ?</p>

<hr>

<p>UPDATE - Attempt:</p>

<p>Based on comments, I also tried to execute the git log command directly without storing it in a variable as follows :</p>

<pre><code>team=( ashraf.bashir diego.palacios )

function create_commits_log_file () {
    authors=''
    for author in "${@}"
    do
        authors="$authors --author $author "
    done
    git log $authors --since yesterday --reverse --pretty=format:\"%h - %an , %ad : %s\" &gt;commits.txt
}

create_commits_log_file "${team[@]}"
</code></pre>

<p>But I am still getting the same error</p>