[squeak-dev] [ANN] DoItFirst command line goodie on SqueakSource

David T. Lewis lewis at mail.msen.com
Sun Dec 6 20:10:44 UTC 2020

On Sun, Dec 06, 2020 at 10:50:13AM -0800, tim Rowledge wrote:
> > On 2020-12-06, at 6:46 AM, stes at PANDORA.BE <stes at telenet.be> wrote:
> > 
> > First of all the script also uses FileStream stdout, and shows how
> > to use nextPutAll to write to stdout.  Also it shows how to time a block.
> I hope those are all useful things to learn; the stdout thing may be an issue, at least for the 5.3 release image.
> > 
> > For me on Squeak VM 4.19.2 I get an error however from the first line:
> > 
> > bash-4.4$ head -1 FibonacciTestScript.st 
> > #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image
> Ah, right, now I remember. We had some fascinating discussions about this area  and that line was added because it means you can set the file permissions to executable and simply run the fibonacci file as a unix script; the #!/usr/bin/squeak will actually run the vm, pass it the following words and thus run the system with this script. Neat, eh? Dig into the list archives for May 2019 (which was about 300 years ago IIRC) and subject 'Faster fibonacci' and related stuff. Subbu suggested some extra-neat ways of making Squeak do scripty-things using the unix script-handler.

There is a preference for "Read document at startup" that needs to be enabled
in order for this to work.

In addition, you will need to set the script file to be executable:

$ chmod +x FibonacciTestScript.st

Then edit the first line of the file to match your own local system.
Tim's script starts with:

#!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image

On my computer, the executable script for running Squeak VMs is
called /usr/local/bin/run rather than /usr/bin/squeak, and the 
particular image that I am running at the moment is called squeak.12.image,
so I edited the line in my script file to look like this:

#!/usr/local/bin/spur64 squeak.12.image

So now the FibonacciTestScript.st file is a Unix executable shell
script, and I can run it like this:

$ ./FibonacciTestScript.st

You can google "unix shebang" to find explanations of how this works.
The basic idea is that the script file runs some program specified
in the comment (starts with #) on the first line of the script, then
it passes itself as an additional parameter to whatever program it ran.
So Unix thinks it's a shell script, and Squeak thinks it's a Smalltalk
start document. The shell script starts Squeak, and then feeds itself
back into Squeak as the start documemt.

According to Wikipedia:

  "The shebang was introduced by Dennis Ritchie between Edition 7 and 8 at Bell Laboratories"

Not bad for a 35-plus year old shell hack, eh?


More information about the Squeak-dev mailing list