Normally a RISC OS command will display any output on the screen, and take input from the keyboard. We can change this using redirection.
*Help Modules { > RAM:$.Modules }
This command saves the list of module titles and versions to a file on the RAM disc. Note that the spacing within the curly brackets is exact, it won’t work if you have too much or little.
*BASIC { < RAM:$.Setup }
This starts the BASIC interpreter, inputting lines from Setup as if you typed them at the keyboard. For example your Setup file might be
TEXTLOAD "RAM:$.Program"
LISTO %1011
LSIT
SAVE "RAM:$.Tokenised"
If you try this out, you’ll see that once it’s run out of lines to read from the Setup file, you can type from the keyboard as normal.
These input and output redirections can be combined, in either order.
*BASIC { < RAM:$.Setup > RAM:$.List }
You can use redirection stop the output of a command appearing
*RMLoad AModule { > null: }
Note that C programs have their own redirection sytem in addition to that provided by the OS CLI.
The redirection above applies to a single command. There is a different way to apply redirection to several commands at a time.
*Spool RAM:$.Directories
*Dir SDFS::RISCOSpi.$.Scores
*Cat Brahms
*Cat Mozart
*Cat Slade
*Spool
The first *Spool turns on spooling, sending any further screen output to the Directories file instead. The second *Spool with no argument turns of spooling, so screen output goes back to normal.
*Exec RAM:$.Setup
*BASIC
*Exec
This is similar to *Spool, but applies to keyboard input instead.
A variable has a value assigned using *Set
*Set MyApp$Running Yes
Its value can be used later, by writing the name of the variable in angle-brackets:
If "<MyApp$Running>" = "Yes" Then Echo MyApp is running Else MyApp is not running
will therefore be executed as
If "Yes" = "Yes" Then Echo MyApp is running Else MyApp is not running
Unfortunately it’s not always obvious when a command will handle variable values in its arguments. If it doesn’t, you can use *Do
*Do ACommand <Obey$Dir>
which puts in the value of Obey$Dir, before passing it to ACommand.
As a general rule, variables will always work in filenames.
You can use *Show to find out the value of a variable, or list all the variables currently assigned.
*Show MyApp$Running
*Show *
While you could find out the value of MyApp$Running by
*Echo MyApp$Running
that method will not distinguish between a variable that has been unset:
*Unset MyApp$Running
and one that has been set to a zero-length string:
*Set MyApp$Running ""
Also it won’t tell you whether a variable is a number or string
*Set Var$1 0
*SetEval Var$2 0
*Echo <Var$1> <Var$2>
0 0
Argument substitution works either using macro variables or inside obey files. Here’s an example using a macro variable.
*SetMacro Alias$MyMacro Echo The first argument is '%0', and the second argument is '%1'.
*MyMacro First Second
The first argument is 'First', and the second argument is 'Second'.
Note that we’ve used *SetMacro, so the CLI knows to do substitution, and we’ve called the variable Alias$MyMacro so that it defines a command *MyMacro.
The asterisk syntax %*n
means substitute argument n
but also anything after that, so
*SetMacro Alias$MyMacro2 Echo First is '%0', second is '%1', the rest is '%*2'.
*MyMacro First Second Third Fourth Fifth
First is 'First', second is 'Second', the rest is 'Third Fourth Fifth'.