K
K
Kamikaze10242017-06-02 15:18:19
linux
Kamikaze1024, 2017-06-02 15:18:19

How to write sqlite3 output to bash variable?

I want to write the output of sql3 to a shell variable in the provided script.

#!/bin/sh

sqlite3 test.db <<EOF
create table n (id INTEGER PRIMARY KEY,f TEXT,l TEXT);
insert into n (f,l) values ('john','smith');
select * from n;
EOF

exit 0;

How can I do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
A1estro, 2017-06-02
@A1estro

Like this for example:

#!/bin/sh

output=`sqlite3 test.db <<EOF
create table n (id INTEGER PRIMARY KEY,f TEXT,l TEXT);
insert into n (f,l) values ('john','smith');
select * from n;
EOF`
echo $output
exit 0;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question