title: Testing variable against sqlite isn't working
body: <p>I'm writing a script that will download certain subdirectories and their contents once only. To do that I've set up an sqlite database (dir.db) with one table (zero) and one column (episode, defined as variable character using VARCHAR(10)). This is used in the following script -</p>
  
  <pre><code>enter #!/bin/sh
  set -x
  cd ~/scripts/sqlite/remote/
  Progs=( * )
  for show in "${Progs[@]%*/}"; do
    cd ~/scripts/sqlite/
    exists=$( sqlite3 dir.db "select count(*) from zero where episode=\"?$show%/}\"" )
    if (( exists &gt; 0 )); then
      echo "Show already downloaded"
    else
      cp ~/scripts/sqlite/remote/${show}/ -t ~/scripts/sqlite/home/ -R -v
      sqlite3 dir.db "insert into zero (episode) values ('${show}');"
      fi
  done
  exit 0
  </code></pre>
  
  <p>This script runs without error, but doesn't work :). If I put a directory in ~/scripts/sqlite/remote/ which is in dir.db, the directory should return 'Show already downloaded', but instead it copies. </p>
  
  <p>Clearly the problem is here - </p>
  
  <pre><code>  exists=$( sqlite3 dir.db "select count(*) from zero where episode=\"?$show%/}\"" )
    if (( exists &gt; 0 ));
  </code></pre>
  
  <p>but I don't know how to diagnose it - I got the code from elsewhere (<a href="http://www.linuxquestions.org/questions/linux-software-2/bash-script-how-to-assign-variable-to-an-sqlite3-command-with-variable-embedded-4175453829/" rel="nofollow">http://www.linuxquestions.org/questions/linux-software-2/bash-script-how-to-assign-variable-to-an-sqlite3-command-with-variable-embedded-4175453829/</a>)</p>
  
  <p>Any thoughts on how to fix would be welcome.</p>