The SBCL manual describes three useful options
--noinform
Suppress the printing of any banner or other
informational message at startup. This makes it easier to write Lisp
programs which work cleanly in Unix pipelines. See also the --noprint
and --disable-debugger
options.
--eval command
After executing any initialization file, but before starting the read-eval-print loop on standard input, read and evaluate
the command given. More than one --eval
option can be used, and all
will be read and executed, in the order they appear on the command
line.
--load filename
This is equivalent to --eval '(load "filename")'
. The special syntax is intended to reduce quoting headaches when invoking
SBCL from shell scripts.
Given a file test.lisp
with contents
(defun hello-world ()
(print 'hello-world)
(terpri))
we can do this with SBCL:
$ sbcl --noinform --load test.lisp --eval '(progn (hello-world) (sb-ext:quit))'
HELLO-WORLD
The (progn ... (sb-ext:quit))
makes sure that the program ends after executing (hello-world)
. Otherwise you get dropped into the SBCL prompt. Since code is compiled automatically in SBCL, the function that you're running is already compiled by the time (hello-world)
is run. If you've compiled the file in advance, you can pass the compiled file to --load
. E.g.,
$ sbcl --noinform --load test.fasl --eval '(hello-world)'
HELLO-WORLD
In fact,given the equivalence of --load
to --eval (load "filename")
, you can just use the base of the file name, and if there's a compiled version, then SBCL should load that, and if there's not, then SBCL will load the source file and you'll get compiled code that way. E.g., in the following, we use just --load test
:
$ sbcl --noinform --load test --eval '(hello-world)'
HELLO-WORLD