title: Put results of mysql command line query into bash script variable
body: <p>I am having a really difficult time figuring out how to get the results of a mysql query into a bash shell script variable.</p>
  
  <pre><code>testDBName="some_database_name"
  mysqlUser="root"
  mysqlPassword="password"
  mysqlCmd="/Applications/MAMP/Library/bin/mysql -u $mysqlUser -p $mysqlPassword -B -N"
  cmdRes=$($mysqlCmd -e 'SHOW DATABASES LIKE "$testDBName"') #THIS IS THE TROUBLESOME LINE
  if [ "$cmdRes" = "" ]; then
      echo "Table does not exist"
  else
      echo "Table already exists"
  fi
  </code></pre>
  
  <p>The line that is giving me the trouble is "cmdRes=...". If I just hard-code a table name into that it works fine, like this:</p>
  
  <pre><code>cmdRes=$($mysqlCmd -e 'SHOW DATABASES LIKE "some_database_name"')
  </code></pre>
  
  <p>But I cannot wrap my head around how/why/what is going on when I have a $variable inside that thing. Based on answers to a lot of other similar-but-different questions, I've tried putting different portions of the string into different variables to cut down on quoting, I've tried single quotes, double quotes, backslashes, double-single-double quotes, curly braces, running eval, etc. -- but nothing is working.</p>
  
  <p>Thanks for any help you can provide.</p>