3

I'm having trouble with my SQLite Select called from a bash script. I'm trying to get a single value from myDB.db and store it to the variable "result".

result=sqlite3 /media/0CBA-1996/logfiles/SQLite3Database/myDB.db "SELECT energy FROM SmartMeter WHERE Timestamp= date('now') LIMIT 1";

echo $result

The problem seems to be with the quotations cause when I leave out "WHERE Timestamp= date('now')" I get a return from the database.

Any ideas ? Thanks Mick

1
  • if it was the quotes, then a simple select date('now') would also fail. Commented Mar 3, 2014 at 20:17

1 Answer 1

8

normally you want the OUTPUT to become the variables value:

result=$(sqlite3 /media/0CBA-1996/logfiles/SQLite3Database/myDB.db "SELECT energy FROM SmartMeter WHERE Timestamp= date('now') LIMIT 1")

echo $result

you nee to use $() or `` like this

result=`sqlite3 /media/0CBA-1996/logfiles/SQLite3Database/myDB.db "SELECT energy FROM SmartMeter WHERE Timestamp= date('now') LIMIT 1" `

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

Comments

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.