title: What is the proper quoting to assign an interpolated sqlite3 query to a variable in Bash?
body: <p>I am trying to assign the output of the following to a variable</p>
  
  <pre><code>sqlite3 /home/user/db_fake_book_index "select id, page from fb2 where bookcode='$bookcode' and page=$page
  </code></pre>
  
  <p>If I run quote it like</p>
  
  <pre><code>echo "sqlite3 /home/user/db_fake_book_index \"select id, page from fb2 where bookcode='$bookcode' and page=$page\""
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>sqlite3 /home/user/db_fake_book_index "select id, page from fb2 where bookcode='557S' and page=10"
  </code></pre>
  
  <p>and if I copy it to a console it works fine, but if i encase it in $() in my script it does not work, sqlite believes there are too many variables, it seems my double quotes are being removed. </p>
  
  <pre><code>$(printf "sqlite3 /home/user/db_fake_book_index \"select id, page from fb2 where bookcode='$bookcode' and page=$page\"")
  </code></pre>
  
  <p>This gives the same faliure</p>