title: execute bash variable (contains another variables) as a command and assign the result to a variable
body: <p>I see that similar questions were answered before but my scenario is a little bit different:</p>
  <ul>
  <li>I need to store a command in a variable in order to I can log it before running</li>
  <li>the command contains variables that can contain space between the words</li>
  <li>the result of the execution must assign to a new variable</li>
  </ul>
  <p><strong>This is the command that works properly from the terminal:</strong></p>
  <pre><code>java -jar ${ORACLE_HOME}/bin/sql-command-line-tool/sql-runner-0.2.2-with-dependencies.jar -v -U ${DB_USERNAME} -P ${DB_PASSWORD} -j jdbc:oracle:thin:@${DB_HOST}:${DB_PORT}/${DB_NAME} &quot;select 1 from dual&quot;
  </code></pre>
  <p><strong>Variables:</strong></p>
  <ul>
  <li>DB_HOST=oracle-db</li>
  <li>DB_PORT=1521</li>
  <li>DB_NAME=ORCLPDB1.localdomain</li>
  <li>DB_USERNAME=&quot;SYS as SYSDBA&quot;</li>
  <li>DB_PASSWORD=Oradoc_db1</li>
  </ul>
  <p><strong>Test:</strong></p>
  <pre><code>$ echo $DB_USERNAME
  &quot;SYS as SYSDBA&quot;
  </code></pre>
  <p>This is how I want to use but this does not work:</p>
  <pre><code>echo &quot;checking whether database server is up and running...&quot;
  _COMMAND=&quot;java -jar ${ORACLE_HOME}/bin/sql-command-line-tool/sql-runner-0.2.2-with-dependencies.jar -v -U ${DB_USERNAME} -P ${DB_PASSWORD} -j jdbc:oracle:thin:@${DB_HOST}:${DB_PORT}/${DB_NAME} \&quot;select 1 from dual\&quot;&quot;
  echo &quot;command: $_COMMAND&quot;
  _RESULT=$($_COMMAND)
  _SHOW_MESSAGE=true
  
  while [[ ${_RESULT} ]]
  do
      if [ $_SHOW_MESSAGE = &quot;true&quot; ]; then echo &quot;the database server is not running yet, waiting...&quot;; fi
      if [ $VERBOSE = &quot;false&quot; ]; then _SHOW_MESSAGE=&quot;false&quot;; fi
      sleep 0.5
      _JSON=$($_COMMAND)
  done
  echo &quot;database server is up and running&quot;
  </code></pre>
  <p>Error:</p>
  <pre><code>Unmatched arguments from index 4: 'SYSDBA&quot;', '&quot;select', '1', 'from', 'dual&quot;'
  </code></pre>
  <p>The jar I use is available from <a href="https://github.com/zappee/sql-runner/tree/master/bin" rel="nofollow noreferrer">here</a>.</p>
  <p>I have tried to use single and double quotes in different ways, tried to use <code>eval</code> but non of them worked properly.</p>
  <p>What I missed?</p>