0

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.

  • 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 Answer 1

1

You're goofing on your quotes.

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply. It works! Just one more question. As I understand - "$blah" --> will throw it as a character. But '$blah' will throw it the value within the variable Am I correct?
No. Single quotes inhibit parameter substitution, which is why you close them first and then open double quotes, and then do it backwards after.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.