SQLite Forum

sqlite3 '-batch' option appears undocumented
It should cause an "exit code" to be returned when the process terminates.  An "interactive process" (one that does not have -batch specified) does not return a failure (non-zero) exit code because it is not possible for an interactive process to exit other than successfully (though opinions may vary, it is a fact, though I suppose that EOF on the input stream could constitute an ABEND).

A process created using redirection (eg "sqlite3 \<input >output") is an interactive process and as such should always return 0 as the exit code notwithstanding any transient failure other than process ABEND (such as the previously mentioned EOF condition, perhaps).  Contrast with "sqlite3 -batch \<input >output" which should return a non-zero exit code only in the event that the process ABENDed -- an EOF on the input stream is NOT an ABEND.

An examination of the shell.c code would be necessary to determine if this is indeed what the -batch option does.  However, this is the "normal" meaning of such options converting an "interactive" program to "batch" operation. It is what an one would expect such a parameter to mean.

Note also -bail which will presumably make a -batch exit immediately when encountering an error.

Rudimentary testing indicates that -batch forces "batch" mode even if the input is from a tty (console) (basically, that there is no interactive prompt issued).  It may affect the process return code, but I have not tested that.

-bail only has effect when in "non-interactive mode", that is the input is not from a tty (console) *or* -batch is specified.