[Openmcl-devel] Running ccl as a shebang script

Zach Beane xach at xach.com
Thu Feb 16 05:44:24 PST 2017


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)

Then:

    $ ./ccl-script.sh 42
    Hello, world. Args: ("ccl" "-n" "--quiet" "--load" "./ccl-script.sh"
"--" "42")
    What's your name? Bob

    Hello, Bob

I learned it from Rob Warnock, who offers a few variations at
http://xach.com/rpw3/articles/54KdndLa5cO9DErd4p2dnA%40speakeasy.net.html
and elsewhere in his archive.

Zach



On Thu, Feb 16, 2017 at 6:16 AM, Tim Bradshaw <tfb at tfeb.org> wrote:

> What I do is something like this:
>
> #!/bin/sh -
>
> exec ccl -Q -b <<EOF
> (print "hi")
> EOF
>
> Which I think is perhaps not as robust, but works (note this depends on my
> ccl wrapper but that's mostly just a thing to avoid having to know what
> obscure path the executable is sitting in & to support recompiling &c).
>
> --tim
> > On 16 Feb 2017, at 00:20, Ron Garret <ron at flownet.com> wrote:
> >
> > Running ccl as a shebang script is not a supported feature.  It turns
> out that it’s possible to do it, but it requires some horrible hackery: you
> have to define a reader macro that treats #! as a comment delimiter, and
> you have to put that in your ccl-init file.  That seemed too ugly to me, so
> I wrote a little C program that reads past the first line of the script and
> pipes the rest into ccl’s stdin.  That seemed like a cleaner solution.
> Just in case anyone else cared about this I thought I’d share the code:
> >
> >
> > ➔ cat cclsh.c
> > #include <stdlib.h>
> > #include <unistd.h>
> > #include <stdio.h>
> > #include <fcntl.h>
> >
> > char *args[] = {"cclsh", "-Q", "-b"};
> >
> > int main(int argc, char *argv[], char *envp[]) {
> >  if (argc!=3) {
> >    fprintf(stderr, "Usage: %s [path-to-ccl-executable] [path-to-script]",
> >           argv[0]);
> >    exit(-1);
> >  }
> >  int fd = open(argv[argc-1], O_RDONLY);
> >  char c = ' ';
> >  while (c!='\n') read(fd, &c, 1);
> >  fclose(stdin);
> >  dup(fd);
> >  close(fd);
> >  execve(argv[1], args, envp);
> > }
> >
> >
> > Example:
> >
> > ➔ cat test
> > #!cclsh /Users/ron/devel/ccl/active/dx86cl64
> > (list 1 2 3)
> > ➔ ./test
> > (1 2 3)
> >
> > rg
> >
> > _______________________________________________
> > Openmcl-devel mailing list
> > Openmcl-devel at clozure.com
> > https://lists.clozure.com/mailman/listinfo/openmcl-devel
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20170216/cf4fa43a/attachment.htm>


More information about the Openmcl-devel mailing list