ShellScripting

A description of how to write Lisp code to be invoked as a command from Unix shells.

You can make your Common Lisp software usable from the Unix command with the cl-launch utility. Or you can use manually one of the techniques below.

The techniques presented here are using CLISP. Similar techniques for CMUCL are given on the CMUCL Hints page.

Simply begin all your Lisp scripts with the line:

#!/usr/bin/clisp

or, alternatively, (the advantage here is that it doesn't rely on the location of clisp),

#!/bin/bash
#|
source ~/.bashrc
exec clisp -q $0 $@
echo Couldn't exec clisp.
exit
|#

and chmod them executable. (You can add -q to the command line to avoid printing CLISP's startup banner). See CLISP manual for other command line options and implementation notes for more information on CLISP scripting.

If you are not using CLISP, you will need to add the following code (at the end will do) to your implementation-specific init file, e.g., for CMUCL, ~/.cmucl-init.lisp (create that file if it doesn't exist):

(set-dispatch-macro-character #\# #\!
                              (lambda (stream bang number)
                                (read-line stream)
                                t))

This is necessary to make your lisp cope with the first line of your script. (CLISP knows about this already).

You don't have to do anything special with chmod on that file.

If you are using CLISP, the variable *args* contains your commandline arguments.


system programming deployment?

This page is linked from: Creating Executables   Macro Characters  

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively