Squeak scripts in UNIX

Lex Spoon lex at lexspoon.org
Tue Feb 13 17:04:42 UTC 2007


The goal is great.  Squeak users are only helped by having more
interfaces to the outside world.  Calling it backwards is just silly;
most of us would like a programming system we can use today, not in
some imagined future where Unixy systems are obsolete.  Unixy systems
are very popular right now, and so we should support interfacing to
them, including via the script-files form of executable.

A nit with your explanation, by the way: it's #!, not # by itself.
The # is a "hash", and the ! is a "bang", and thus #! is "hashbang"
which, now that you mention it, does sound like "shebang" :) .


On the technical side, feel free to propose a changeset that updates
the image however you need.  Is there any legacy we need to worry
about whatsoever?


As a general approach, a kind of header that works well would look
something like this:

  #!/bin/sh
  exec squeak -headless -- "$0" "$@"
  !#

What happens here is that the Unix kernel starts starts /bin/sh on the
script file, but /bin/sh sees only a single "exec squeak" command.
The arguments are "--", which tells the Debian squeak script not to
try and interpret any later arguments.

The advantages of this approach over using #!/usr/bin/squeakvm are:

  1. You can supply arguments to squeak if you
  want, e.g. -headless.  I am told this is non-portable
  on the #! line.

  2. You can find squeak via $PATH instead of needing it
  to be hardcoded.


This requires two changes in the standard Squeak image to work.

First, the above approach requires that the image allows files as
arguments, not just URL's.  I see no reason not to support both: if it
starts with "[a-z]+:", then it's a URL, othrewise it's a file.

Second, we need a way to support a block comment at the head of the
script.  In the example above I used #!...!#, which I like.  It
has a tiny bit of synergy in that it is what scsh and scala also
use for their script files.  However, we are free to do whatever
we want; it's not a big deal.

To implement #!...!# (or whatever else), the best solution forward
appears to be to have the script-running code in the image strip off
the header.  Technically it would be nicer if this was a valid
notation for comments in Squeak, but that's a language change and
would require negotiating with all of Squeakdom.



Anyway, again, go go go.  :) I would love to see better scripting on
Unix, and the first step to doing it well is a clean interface for
running these things at all.


Lex



PS -- There was a time in history when image files were directly
executable on Unix.  The trick is simply to put a proper #! header on
*image* files, and to make sure that the header is exactly 512 bytes.
I don't know why that change got backed out.  It was a simple
implementation and was convenient for Unix-based Squeakers.




More information about the Squeak-dev mailing list