title: How to pass quoted arguments from variable to bash script
body: <p>I tried building a set of arguments in a variable and passing that to a script but the behavior different from what I expected.</p>
  
  <p><strong>test.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  for var in "$@"; do
    echo "$var"
  done
  </code></pre>
  
  <p><strong>input</strong></p>
  
  <pre><code>usr@host$ ARGS="-a \"arg one\" -b \"arg two\""
  usr@host$ ./test.sh $ARGS
  </code></pre>
  
  <p><strong>output</strong></p>
  
  <pre><code>-a
  "arg
  one"
  -b
  "arg
  two"
  </code></pre>
  
  <p><strong>expected</strong></p>
  
  <pre><code>-a
  arg one
  -b
  arg two
  </code></pre>
  
  <p>Note if you pass the quoted arguments directly to the script it works.  I also can work around this with eval but I wanted to understand why the first approach failed.</p>
  
  <p><strong>workaround</strong></p>
  
  <pre><code>ARGS="./test.sh -a "arg one" -b "arg two""
  eval $ARGS
  </code></pre>