Scripting site map

Introduction
You can type commands into a text file (or "script") for CD Shell to batch execute. This makes things such as interactive menu systems and custom programmable boot sequences possible. Script files can be no larger than 65535 bytes. You can see examples of some scripts here.

Script Debugger
After you've read through this section of the documentation and you want to begin making scripts, the best way to get started is to use the script debugger (cdshw.com, included in the release package). Most console and script commands will work in the debugger, so it's much easier to test your scripts from within DOS or Windows (the debugger only works in a DOS-compatible environment) instead of burning them to a disc.

Commands such as boot, reboot, etc. will not follow through with their actions in the script debugger, so you don't have to worry about them causing problems. They will terminate the currently running script, however.

When everything seems to be working right in the debugger, I suggest burning a rewritable disc to make sure the script works as intended. Then if you have errors you can always erase the disc and try again. After you have all the kinks worked out, go ahead and produce your final CD.


Script Line Format
label: command [param1] [param2]...[paramN]     # comment
Any line in a script file can contain up to three optional fields: label, command, and comment. You can omit any or all of these fields on a line, but if you include them they have to be in the standard format shown above. The current line length limit in CD Shell is 255 characters.
Labels
If you include a label on the line, it doesn't have to be at the very beginning of the line, but it must begin at the first non-whitespace on the line. A label definition must be followed by a colon; when you refer to a label in a call or goto command, you don't include the trailing colon. Labels can consist of any combination of characters except ':' (colon), ';' (semicolon), and '#'.

To use labels effectively, it's important to realize how they are searched for by the script interpreter. When you specify a label in a call or goto command, the interpreter begins searching for the label at the next line, and continues to the end of the file. If the label it's searching for is not found by the time the end of the file is reached, then the search resumes at the beginning of the file. If by the time the search reaches the original call/goto statement the label is not found, an error is generated reporting the unresolved label and the line number it was referenced on, and script processing is terminated. Note that there is no detection of duplicate label definitions. The first label found that matches the one referenced is the one used for the destination of the call/goto command.

Commands
A command is any CD Shell script command, including its parameters. You type them just as you would at the command prompt for console commands. Consult the Command Reference for information on the proper use of each command.
Comments
A comment begins with a pound sign (or hash), and continues to the end of the line. In other words, the script processor interprets the '#' as an end-of-line character; upon finding one the rest of the line is ignored and script processing continues with the following line. All comments are single-line comments (there is no such thing as a multi-line comment in CD Shell).

Multiple commands per line
You can place multiple commands on a single line by separating them with a semicolon (';'). CD Shell will execute them one at a time just as if they were written on separate lines. Commands cannot span multiple lines, however.

When an error is reported in a script, you will see something like this:


Error: Unknown command entered.
[Command: foo] [Line:15.3] [File:cdshell.ini]

This means that the error occured in the third command on the fifteenth line, in the file "cdshell.ini".

Expressions
Some commands that are used in scrips operate based on the result of a mathematical calculation. These are expressed very much like they are in the programming language 'C'. Most of the standard 'C' operators are available, and you can even use functions to return a value in the middle of an expression. Below is a list of supported operators, grouped according to precedence. All operations are carried out with a precision of 32-bits. Oh yeah, and it's all integer math -- no floats allowed. :)

OperatorDescription
(Open parenthesis
)Close parenthesis
-Negate
!Logical Not
~One's complement (bitwise not)
*Multiply
/Divide
%Modulo
+Add
-Subtract
<<Left shift
>>Right shift
<Less than
>Greater than
<=Less than or equal
>=Greater than or equal
==Equal
!=Not equal
&Bitwise and
^Bitwise xor
|Bitwise or
&&Logical and
^^Logical xor
||Logical or


- Previous - - Next -