Subject: Re: #! /usr/local/bin/lisp ?
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 10 Oct 2008 20:49:52 -0500
Newsgroups: comp.lang.lisp
Message-ID: <5PSdnWxIW8Xdm23VnZ2dnUVZ_vudnZ2d@speakeasy.net>
cartercc  <cartercc@gmail.com> 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]:

      http://rpw3.org/hacks/lisp/site-switch-script.lisp

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
      /usr/local/bin/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:

    http://www.cliki.net/CMUCL%20Hints
    ...
    Running Lisp programs from the shell prompt
    ...[method#1]...
    
    (also see [this page])
	      http://users.actrix.co.nz/mycroft/runlisp.html

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

Still more general methods:

    http://www.cliki.net/ShellScripting

    http://www.cliki.net/cl-launch

    http://www.cliki.net/Creating%20Executables


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607