Shell scripting and sqlite3
===

Scenario:
I am trying out a small shell scripting program.

In this program- I am trying to query a database with 2 tables. and trying to get a yes or no answer. 

The etag = md5sum that I fetch from the file using a python script. 

    echo 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='$etag''

 When I try to print it on my screen it shows it clearly that etag as the md5sum

But, If I try to query it on my database and try to fetch the result.  using the script given below

    sqlite3 hashez.db 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='$etag''


This is the error that I get.
    Error: unrecognized token: "579f0b61cf958a0eea2f60906e6a04a4"

After googling a little bit, this the solution I found from this [link][1]

Then I changed it to ${#etag}

    echo 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='${#etag}''

The error that I get now is 

    select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and **b.hashuser=32**

Why is b.hashuser=32. is my first question.

Second problem:

When I try to query the database using the above function:

sqlite3 hashez.db 'select a.hash,b.hashuser, case when a.hash=b.hashuser then "No!" else "yes!" end from tempo b, hashes a where a.hash=b.hashuser and b.hashuser='${#etag}''

I got no reply back.

- Is my query wrong. , If yes, why am I getting an answer when I query it directly on the database?

Sorry for my bad english



  [1]: http://www.unix.com/shell-programming-scripting/146376-execution-problem-shell-script.html
