2021-01-21 13:40:28 +01:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
|
|
<title>.</title>
|
|
|
|
<style type="text/css">
|
|
|
|
|
|
|
|
* { color: #000; background: #fff; max-width: 700px; }
|
|
|
|
tt, pre { background: #dedede; color: #111; font-family: monospace;
|
|
|
|
white-space: pre; display: block; width: 100%; }
|
|
|
|
.indentedcode { margin-left: 2em; margin-right: 2em; }
|
|
|
|
.codeblock {
|
|
|
|
background: #dedede; color: #111; font-family: monospace;
|
|
|
|
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
|
|
|
|
padding: 7px;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.indentedlist { margin-left: 2em; color: #000; }
|
|
|
|
|
|
|
|
span { white-space: pre; }
|
|
|
|
.text { color: #000; white-space: pre; background: #dedede; }
|
|
|
|
.colon { color: #000; background: #dedede; }
|
|
|
|
.note { color: #000; background: #dedede; }
|
|
|
|
.str { color: #000; text-decoration: underline; background: #dedede; }
|
|
|
|
.num { color: #000; background: #dedede; font-weight: bold; font-style: italic; }
|
|
|
|
.fnum { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.ptr { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.fetch { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.store { color: #000; font-style: italic; background: #dedede; }
|
|
|
|
.char { color: #000; background: #dedede; }
|
|
|
|
.inst { color: #000; background: #dedede; }
|
|
|
|
.defer { color: #000; background: #dedede; }
|
|
|
|
.imm { color: #000; font-weight: bold; background: #dedede; }
|
|
|
|
.prim { color: #000; font-weight: bolder; background: #dedede; }
|
|
|
|
|
|
|
|
.tt { white-space: pre; font-family: monospace; background: #dedede; }
|
|
|
|
|
|
|
|
.h1, .h2, .h3, .h4 { white-space: normal; }
|
|
|
|
.h1 { font-size: 125%; }
|
|
|
|
.h2 { font-size: 120%; }
|
|
|
|
.h3 { font-size: 115%; }
|
|
|
|
.h4 { font-size: 110%; }
|
|
|
|
.hr { display: block; height: 2px; background: #000000; }
|
|
|
|
</style>
|
|
|
|
</head><body>
|
|
|
|
<p><span class="h1">Unix Scripting</span>
|
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
RETRO on Unix hosts is designed to play well with scripting.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
Shebang
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
To run an entire program directly, start the file with the standard
|
|
|
|
shebang and make the file executable:
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>#!/usr/bin/env retro</tt>
|
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
This requires the retro binary to be in your path.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Arguments</span>
|
|
|
|
<br/><br/>
|
|
|
|
RETRO provides several words in the <span class="tt">script:</span> namespace for accessing
|
|
|
|
command line arguments.
|
|
|
|
<br/><br/>
|
|
|
|
The number of arguments can be accessed via <span class="tt">script:arguments</span>. This
|
2021-03-22 13:18:17 +01:00
|
|
|
will return a number with the arguments, other than the script name.
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>script:arguments '%n_arguments_passed\n s:format s:put</tt>
|
|
|
|
<br/><br/>
|
|
|
|
To retreive an argument, pass the argument number to <span class="tt">script:get-argument</span>:
|
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
<tt class='indentedcode'>script:arguments [ I script:get-argument s:put nl ] indexed-times</tt>
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
And to get the name of the script, use <span class="tt">script:name</span>.
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>script:name s:put</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<span class="h2">Mixing</span>
|
|
|
|
<br/><br/>
|
2021-03-22 13:18:17 +01:00
|
|
|
With use of the Unu literate format, it's possible to mix both shell
|
|
|
|
and RETRO code into a single script. As an example, this is a bit of
|
|
|
|
shell that runs itself via retro for each .retro file in the current
|
|
|
|
directory tree:
|
2021-01-21 13:40:28 +01:00
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>#!/bin/sh</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'># shell part</tt>
|
|
|
|
<tt class='indentedcode'>find . -name '*.retro' -print0 | xargs -0 -n 1 retro $0</tt>
|
|
|
|
<tt class='indentedcode'>exit</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'># retro part</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>This will scan a source file and do something with it:</tt>
|
|
|
|
<br/><br/>
|
|
|
|
<tt class='indentedcode'>~~~</tt>
|
|
|
|
<tt class='indentedcode'>... do stuff ...</tt>
|
|
|
|
<tt class='indentedcode'>~~~</tt>
|
|
|
|
</p>
|
|
|
|
</body></html>
|