user3376372
user3376372

Reputation: 31

SQLite Select command in bash

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

Upvotes: 3

Views: 7378

Answers (1)

RobbySherwood
RobbySherwood

Reputation: 361

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

Upvotes: 8

Related Questions