If you're sweating quoting issues in here-documents, you can put the sqlite query in a separate file and tell sqlite to execute that file instead.
Here's a helpful example from SO: https://stackoverflow.com/a/21759264/711585
Here's a helpful example from SO: https://stackoverflow.com/a/21759264/711585
sqlite3 database.db <query.sql
Some other DBMS have similar things, for MariadDB you could write it in a ".sql" file as well, setting variables and use it so that you can write a generic sql file. (seems you can't use the variable thing with sqlite3) MariaDB> SET @username='UserName@localhost';
MariaDB> SET @hostname='localhost';
MariaDB> SOURCE create-user.sql;
Such things is usually cleaner/simpler than writing in bash.You could also read the contents of the query file into a shell parameter with the `read` builtin.