user1524529
user1524529

Reputation: 905

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

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.

Sorry for my bad english

Upvotes: 0

Views: 255

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

You're goofing on your quotes.

somecmd 'SELECT ... "'"$etag"'", ...'

Note the double quotes inside the single quotes, as well as around the parameter substitution.

Upvotes: 1

Related Questions