0

For convenience, I want to make a batch file that opens a terminal, runs SQLite and connects to a database, attaches some other database, and leaves the SQLite terminal open.

For example:

#!/bin/bash

sqlite3 -interactive "/db.sqlite" <<EOS
  ATTACH DATABASE "/sb2.sqlite" AS db2;
EOS

The problem is that sqlite3 quits right after executing the command.

Any ideas on how to leave it open?

1 Answer 1

1

The issue is that sqlite3 automatically exits when it gets an EOF from standard input, which it does at the end of the heredoc. Luckily, one of the command line options it takes is -cmd SQL, which is evaluated before it starts reading from standard input. So, your script might look something like:

#!/bin/sh
sqlite3 -interactive -cmd "ATTACH '/sb2.sqlite' AS db2" /db.sqlite

Alternatively, if you always want this run every time you start the sqlite3 client, you can put it in your ~/.sqliterc file, or use -init /path/to/other/file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.