Exploring the unnecessary, part 3735928559
Spring 2025
A Short Word on AmigaDOS Scripts
Without getting caught up in semantics, AmigaDOS in this text refers to the command line portion of the Amiga computers' operating system. AmigaDOS is based on TRIPOS, but was expanded and added to by both the original Amiga team and then Commodore. One thing that remains basically the same is the parser for shell scripts, or sequence files as they're called in TRIPOS. The script parser is reasonably competent for a 1980:s home computer OS and can be used for solving real world made up programming problems.
The parser accepts a few special directives, such as .KEY, which is used to describe the template for arguments passed to the script file. For example, .KEY FILENAME/A
tells the parser that the script accepts a string argument called FILENAME. These directives are placed at the start of the script file.
By default, the parser does string interpolation using the characters < (less than) and > (greater than). The cleverness of this is debatable: these characters are also used for I/O redirection, which can quickly make things confusing. Luckily, the parser also accepts the directives .BRA and .KET, each followed by a single character, which lets the programmer override the default interpolation characters. The terms BRA and KET are most likely borrowed from Dirac notation.
A Simple Example
Usually, AmigaDOS scripts using interpolation replace the default characters with curly braces, { and }, respectively. This trend may have originated at Commodore. Consider the following script:
.BRA { .KET } .KEY var Echo Hello {var}!
Here, < and > have been substituted with { and }. The script takes a single argument, var, and the string interpolation then replaces {var} with the supplied argument. If saved as the file myscript and executed, the following AmigaShell session can be achieved:
AmigaShell> myscript datagubbe Hello datagubbe! AmigaShell> _
Interpolate This!
This of course begs the question: What characters can be used for string interpolation in shell scripts? Thanks to the tireless efforts of talented researchers at Datagubbe Labs, an answer can be presented - and programmers worldwide can finally get a good night's sleep. Without further ado, let's get down to brass tacks!
Test Tooling
There are text editors on the Amiga that'll happily insert any ASCII character into a text file, but why use an existing solution when you can build your own? An ARexx program - makescript - was quickly hacked together meticulously constructed for the purpose. This program generates an AmigaDOS script file with arbitrary characters for .BRA and .KET, supplied either as plain text or ASCII char codes. The source code for makescript is available here.
Bread and Butter
The defaults and the standard curly substitutes both work very well, as expected. Datagubbe Labs has taken the liberty of preparing screenshots, to further emphasize the validity and rigor of this important research. The scripts can also be downloaded, for transparency and reproducibility. Witness:
Odds and Alphas
What about non-matching character pairs, such as [ and }? That works, too, which was expected. As does standard letters, such as A and B.
Bells and Whistles
Finally, non-printable characters were introduced. First, shift out (SO, decimal char code 14) and shift in (SI, decimal char code 15) were tested. These worked, too. Then, upping the ante, our relentless researchers decided to try the ASCII BEL character (decimal char code 7). AmigaDOS handles the BEL character by flashing the screen when it's encountered in a text. How would this fare in script execution? For closing the interpolation, negative acknowledgement (NAK, decimal char code 21), was chosen. This too, proved to work flawlessly - and no screen flashing was encountered when executing the script.
Another Job Well Done
Naturally, when printing the script file contents to the shell window using the AmigaDOS command Type, these characters cause a bit of commotion. BEL, for example, results in a screen flash as expected. In order to verify that the characters are indeed present in the script files, feel free to download them above - or study this screenshot of MicroEMACS, displaying the non-printable characters as control sequences.
In conclusion, AmigaDOS string interpolation offers both resilience and a wide variety of choice - a cause for celebration as good as any. Thanks for your attention, and happy hacking!