sqlite3: dump schema into .sql file from command line sqlite3: dump schema into .sql file from command line sqlite sqlite

sqlite3: dump schema into .sql file from command line


The shell allows redirection, and sqlite3 can get the command as a parameter:

sqlite3 test.db .schema > schema.sql


Figured it out! I just needed to escape the text in the echo statement:

echo -e '.output schema.sql\n.schema' | sqlite3 test.db


FYI you could also have done

( echo .output schema.sql ; echo .schema ) | sqlite3 test.db

This is running two echo commands in a subshell and piping its output.

Or

sqlite3 test.db <<EOF.output schema.sql.schemaEOF

See How does "cat << EOF" work in bash? for what this is doing.