dimanche 15 février 2015

Testing variable against sqlite isn't working

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 -



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 > 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


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.


Clearly the problem is here -



exists=$( sqlite3 dir.db "select count(*) from zero where episode=\"?$show%/}\"" )
if (( exists > 0 ));


but I don't know how to diagnose it - I got the code from elsewhere (http://ift.tt/1ExbQ7f)


Any thoughts on how to fix would be welcome.


Aucun commentaire:

Enregistrer un commentaire