Subject: Re: #! /usr/local/bin/lisp ?
From: (Rob Warnock)
Date: Fri, 10 Oct 2008 20:49:52 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
cartercc  <> wrote:
| When I write a Perl script and include "#! /usr/bin/perl" as the first
| line, I can chmod it to 755 and run it like "perl ./script.plx".

As others have noted, you probably meant "run it with ``./script.plx''".

| Can I do the same with a Lisp script?

As others have noted, this is not a part of the ANSI Common Lisp
standard, but various implementations [CLISP & SBCL were already
discussed] or their users have provided ways to accomplish it,
since it's *so* useful!

For CMUCL, here's my favorite way [for reasons that should be obvious]:

1. Download the following small hack and install per the instructions given
   within [includes a 3-line tweak to your "library:site-init.lisp" file]:

2. If you've installed CMUCL as "lisp" start your scripts with
   "#!/usr/local/bin/lisp -script", or, if as "cmucl" (as I personally
   prefer) then use "#!/usr/local/bin/cmucl -script".

3. Example:

      $ which cmucl
      $ ls -l hello
      -rwxr-xr-x  1 rpw3  rpw3     172 Nov 24  2007 hello
      $ cat hello
      #!/usr/local/bin/cmucl -script
      (format t "Hello, world!~%")
      (loop for arg in (cons *script-name* *script-args*)
	    and i from 0
	do (format t "argv[~a] = ~s~%" i arg))
      $ ./hello -opt1 foo bar
      Hello, world!
      argv[0] = "./hello"
      argv[1] = "-opt1"
      argv[2] = "foo"
      argv[3] = "bar"

Other ways to do it with CMUCL:
    Running Lisp programs from the shell prompt
    (also see [this page])

    CMUCL shell scripts
    ...[methods #3, #4, #5, etc.]...

Still more general methods:


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607