farmir farmir - 3 months ago 9
Bash Question

run command line sqlite3 query and exit

We can use

-cmd
option with
sqlite3
to run a query, but then
sqlite3
opens the database and waits in there for interactive input. How can we run a query on
sqlite3
from the command line and exit?

Thanks,

Answer

Just include the command in quotes after the database file argument.

For example, the following creates a table called abc:

sqlite3 test.db 'create table abc (col0 int)'
Comments