[Openmcl-devel] Running ccl as a shebang script

Ron Garret ron at flownet.com
Thu Feb 16 15:12:25 UTC 2017


These are all very clever, but I guess I should have been a little more explicit about my motives and concomitant design requirements: I want to be able to use ccl as a shell scripting language without having to jump through any cringe-inducing hoops.  That means I want my script ideally to look like this:

#!/bin/env ccl
(lisp-code)

i.e. no “:” ; hacks, no requirement to call (quit) at the end, no need to put anything special in your ccl-init.  I want it to Just Work.  The reason I want this is because I want to recruit new Lisp programmers, and when one of them says, “I use Python, and I can do this:

#!/bin/env python
python-code

Can Lisp do that?”  I want the answer to be an unqualified, “yes.”

rg


On Feb 16, 2017, at 6:27 AM, Barry Fishman <barry at ecubist.org> wrote:

> 
> On 2017-02-16 08:44:24 +05, Zach Beane wrote:
>> I've used variations on this trick for a long time. ccl-script.sh follows:
>> 
>>    ":" ;
>>    #| Any necessary shell setup can go here
>> 
>>    # Exec into Lisp
>>    exec ccl -n --quiet --batch --load `which "$0"` -- ${1+"$@"}
>> 
>>    # |#
>> 
>>    (format t "Hello, world. Args: ~S~%" ccl:*command-line-argument-list*)
>>    (format t "What's your name? ")
>>    (force-output)
>>    (format t "~&Hello, ~A~%" (read-line))
>>    (ccl:quit)
> 
> Or similarly, since 'ccl' is a script that already does the shell setup:
> 
> --8<---------------cut here---------------start------------->8---
> ":" ; exec ccl --no-init --load "`which $0`" -- ${1+"$@"}
> ;;;; -*- lisp -*-
> (defvar *program* (file-namestring
>                   #.(or *compile-file-truename* *load-truename*)))
> (defvar *args* *unprocessed-command-line-arguments*)
> 
> (format t "Program: ~a~%" *program*)
> (do ((count 0 (1+ count))
>     (args *args* (cdr args)))
>    ((null args))
>  (format t "Arg ~D = ~S~%" count (car args)))
> 
> (quit)
> --8<---------------cut here---------------end--------------->8---
> 
> --
> Barry Fishman
> 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list