Bash: How to run command expecting quotes using a variable?
<p>I have a git command that I would like to run in my script:</p>

<pre><code>git filter-branch -f --env-filter "STUFF HERE IN QUOTES"
</code></pre>

<p>The thing is, in my script I am dynamically creating the string that is represented by <code>STUFF HERE IN QUOTES</code>:</p>

<pre><code>ENVFILTER=""
while read commit; do
    IFS="|" read date hash message &lt;&lt;&lt; "$commit"
    DATE_NO_SPACE="$(echo "${date}" | tr -d '[[:space:]]')"
    COMMIT_ENV=$(cat &lt;&lt;-END
         if [ \$GIT_COMMIT = $hash ]
         then
         export GIT_AUTHOR_DATE="$DATE_NO_SPACE"
         export GIT_COMMITTER_DATE="$DATE_NO_SPACE"
         fi
    END
    )
    ENVFILTER="$ENVFILTER$COMMIT_ENV"
done &lt; $tmpfile
git filter-branch -f --env-filter \'"$ENVFILTER"\' // &lt;---------- does not work
</code></pre>

<p>Basically I start with an empty string <code>ENVFILTER</code> and I concat it with other strings to form a bunch of if statements. I'm having trouble with the last step, which is running the actual command. I don't know how to run it with the expected quotes + the interpolated value.</p>

<p>=== UPDATE ===</p>

<p>After looking at @chepner's answer and using <code>"$ENVFILTER"</code>, I can now successfully run the command. So is answer is correct.</p>

<p>However, there is an error about my <code>if</code> statements (not related to the quotes):</p>

<pre><code>Rewrite eeb8860c13179c931a513a9ada76dc109324d790 (1/17)/opt/boxen/homebrew/Cellar/git/2.6.2/libexec/git-core/git-filter-branch: eval: line 313: syntax error near unexpected token `if'
/opt/boxen/homebrew/Cellar/git/2.6.2/libexec/git-core/git-filter-branch: eval: line 313: `     fi     if [ $GIT_COMMIT =  08a2d85f9412c67435929d80ccc5b914f3ad8547  ]'
env filter failed:      if [ $GIT_COMMIT =  59d13c174c34b6540f61585ef507abcef29ab22e  ]
     then
 export GIT_AUTHOR_DATE="2016-10-02T21:16:37-04:00"
 export GIT_COMMITTER_DATE="2016-10-02T21:16:37-04:00"
     fi     if [ $GIT_COMMIT =  08a2d85f9412c67435929d80ccc5b914f3ad8547  ]
     then
 export GIT_AUTHOR_DATE="2016-08-31T17:54:28-04:00"
 export GIT_COMMITTER_DATE="2016-08-31T17:54:28-04:00"
     fi     if [ $GIT_COMMIT =  d7801396f5fb1092beec3aa484361cd50ab35e9e  ]
     then
 export GIT_AUTHOR_DATE="2016-08-31T17:53:07-04:00"
 export GIT_COMMITTER_DATE="2016-08-31T17:53:07-04:00"
     fi     if [ $GIT_COMMIT =  7930e9be149a57229c9fc26ccffe1c6453317d70  ]
     then
 export GIT_AUTHOR_DATE="2016-08-31T17:48:03-04:00"
 export GIT_COMMITTER_DATE="2016-08-31T17:48:03-04:00"
     fi     if [ $GIT_COMMIT =  f0849b2de99ac37790eaf6e40c8980988e865c7c  ]
     then
 export GIT_AUTHOR_DATE="2016-08-31T17:46:33-04:00"
 export GIT_COMMITTER_DATE="2016-08-31T17:46:33-04:00"
     fi
[
</code></pre>

<p>Is there something wrong with it? I don't get it</p>