Making SQLITE/SQLITE3 executable scripts.
1 2 #! /usr/bin/env bash 3 4 # execute some bash scripting commands here 5 6 sqlite3 mydatabase <<SQL_ENTRY_TAG_1 7 SELECT * 8 FROM mytable 9 WHERE somecondition='somevalue'; 10 SQL_ENTRY_TAG_1 11 12 # execute other bash scripting commands here 13 14 sqlite3 mydatabase <<SQL_ENTRY_TAG_2 15 SELECT * 16 FROM myothertable 17 WHERE someothercondition='someothervalue'; 18 SQL_ENTRY_TAG_2
Note that being in a bash script means that you can expand $-variables inside the SQL code directly. This is, however, not advised unless you can be sure that only trusted, competent people will run your code. Otherwise you'll be facing SQL injection attacks.