p>. [[CLI Basics part 1|<< Part 1]] | [[CLI Basics|Index ^^]] | [[CLI Basics part 3|Part 3 >>]] --- <div id="toc_heading"></div><div id="toc"></div> h2. Redirection Normally a RISC OS command will display any output on the screen, and take input from the keyboard. We can change this using redirection. bc. *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. bc. *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 bc. TEXTLOAD "RAM:$.Program" LISTO %1011 LIST 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. bc. *BASIC { < RAM:$.Setup > RAM:$.List } You can use redirection to stop the output of a command appearing bc. *RMLoad AModule { > null: } Note that C programs have their own redirection system in addition to that provided by the OS CLI. Also note that redirection is applied prior to the command-line being processed and is therefore non-conditional. In the following example, two files would be created regardless of the result of the IF statement: bc. IF "x"="y" THEN ECHO Fail { > RAM:$.out1 } ELSE ECHO Good { > RAM:$.out2 } h3. Further redirection The redirection above applies to a single command. There is a different way to apply redirection to several commands at a time. bc. *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 off spooling, so screen output goes back to normal. h2. System variables A system variable has a value assigned using *Set bc. *Set MyApp$Running Yes Its value can be used later, by writing the name of the variable in angle-brackets: bc. If "<MyApp$Running>" = "Yes" Then Echo MyApp is running Else MyApp is not running will therefore be executed as bc. 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 bc. *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. bc. *Show MyApp$Running *Show * While you could find out the value of MyApp$Running by bc. *Echo MyApp$Running that method will not distinguish between a variable that has been unset: bc. *Unset MyApp$Running and one that has been set to a zero-length string: bc. *Set MyApp$Running "" Also, it won't tell you whether a variable is a number or string bc. *Set Var$1 0 *SetEval Var$2 0 *Echo <Var$1> <Var$2> 0 0 h2. Substitution Substitution can be done with Alias$ variables, and inside Obey files. Here's an example using an alias. bc. *Set Alias$MyCommand Echo The first argument is '%0', and the second argument is '%1'. *MyCommand First Second The first argument is 'First', and the second argument is 'Second'. The asterisk syntax <code>%*n</code> means substitute argument <code>n</code> but also anything after that, so bc. *Set Alias$MyCommand2 Echo First is '%0', second is '%1', the rest is '%*2'. *MyCommand2 First Second Third Fourth Fifth First is 'First', second is 'Second', the rest is 'Third Fourth Fifth'. h2. Further reading * [[System Variables]] in the Programmer's Reference Manual. --- p>. [[CLI Basics part 1|<< Part 1]] | [[CLI Basics|Index ^^]] | [[CLI Basics part 3|Part 3 >>]]