Run command-line SQLite 3 query and exit
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)'
You can use the .exit
command (1), to exit gracefully:
sqlite3 test.db "select * from abc;" ".exit"
Documentation: Command Line Shell For SQLite.
If you are stuck in a situation where you absolutely "have to" use the -cmd
flag when you are running SQLite 3 from the command line, you can use successive blank command to exit.
For example:
sqlite3 test.db "select * from urls;" "" > test.txt
In this example, the ""
will cause the SQLite 3 process to exit. (At least it does for me on OS X.)