CREATING COMMAND SEQUENCE FILES (CSF) OR BATCH FILES ##################################################################### INTRODUCTION In your normal use of DOS, you will enter a command and execute it immediately. This is fine for most uses, but occasionally you'll find that you need to repeat a series of commands regularly, or that you'd like to customise the startup-sequence of your WorkBench disk. In fact, the startup-sequence is the most significant of CSFs, and being able to manipulate and change it is one of the fundamental abilities you should develop. In this tutorial you'll learn how to do so, and all the necessary tools are available on your Workbench disk. You will need to know the basic structure of CSFs, and how to edit them. There are some special CSF commands, such as EXECUTE, SKIP, and so forth, which are used in conjunction with normal CLI commands, and there is a SCREEN EDITOR, called ED in your C directory which allows you to create or change such files, as well as any other text file. However, you can create a text file of any kind with a Word Processor which allows you to save a file in strict text form (as ASCII characters). FUNDAMENTALS 1. USING ED, THE TEXT EDITOR [See the summary of ED commands in the REFERENCE drawer.] As mentioned above, you will have to be able to create a text file with a text editor, and your Workbench disk comes with ED, a basic text editor quite capable of this and more. There is another "Line Editor" called EDIT in your C directory as well, but it is not easy to learn. In fact, it would be worthwhile buying a commercial editor such as TxED, or finding one of the excellent editors in the public domain, which make use of the Workbench interface. In the meantime however, if you wish to create a new file, or edit an old one, using ED, simply enter in the CLI ED FILENAME for example ED df0:s/startup-sequence if you want to change your startup-sequence (do it with a COPY of your Workbench!). Now just enter text from the keyboard to create a new file. In the case of editing an existing file, use the cursor keys, DEL and BACKSPACE and RETURN keys to change and add text. Let's say that we want to create a file called MAKERAM which will copy all the CLI commands into RAM, and run them from there instead of from your disk (see further below). Enter the following: ED S/MAKERAM (You'll be presented with the ED screen.) MAKEDIR RAM:C (Hit return) COPY SYS:C RAM:C ASSIGN C: RAM:C You now have a 3-line batch file. If you notice a spelling mistake, simply use the cursor keys to reach the mistake and Backspace or Delete the offending letter(s). Now you must save the file, so press ESC and you'll find the cursor drops to the bottom of the screen where further commands (called EXTENDED COMMANDS as distinct from IMMEDIATE COMMANDS which you use when on the ED screen itself) may be entered. The command to save is simply X, followed by RETURN. This will exit ED, while saving your file under the name you first gave it in the directory you specified - in this case MAKERAM in the S directory. * NOTE - The REFERENCE SECTION of the Manual lists all the available commands for ED, and if you decide to stay with ED, make sure you experiment with them, as they allow you many powerful possibilities for text editing. 2. CREATING A COMMAND SEQUENCE FILE You must create a file with one or more CLI commands, with one command to a line, and with a RETURN character at the end of each line. Having created the file, it is a good idea to save it to the S directory of your disk, since AmigaDOS looks there automatically when you use the command EXECUTE. This means that you don't have to type out the full PATHNAME of the file - ie, where it is, such as df1:utilities/myCSF Instead, you'll simply type EXECUTE myCSF The command EXECUTE (which is detailed below) must precede any CSF, just as it is automatically used when booting up with any Workbench disk. You can also attach comments to your CSF by simply typing in a semi-colon before any comment you make. For example: MAKEDIR RAM:C ;make directory c on the Ram disk COPY SYS:C RAM:C ALL ;copy all your c commands across ASSIGN C: RAM:C ;re-assign your c: directory to ram:c This CSF is a most useful one to have, since it allows you to copy all your CLI commands to a C directory which you've created on your Ram disk, and then, the last line tells the system to look in the Ram:c directory when it wants to find a CLI command. These three lines oould be typed into your startup-sequence to be executed automatically each time that you boot up; or you could simply name this file MAKERAM or some such name, and EXECUTE it whenever you want to. Such a file can be refined as you wish - it may be that you are memory-conscious, and don't want to have a lot of your precious Ram taken up by commands that you rarely use. So you could adapt this CSF to copy only those commands that you use regularly into the RAM:C directory, by replacing the second line above by the following series: COPY SYS:C/CD RAM:C COPY SYS:C/DIR RAM:C COPY SYS:C/TYPE RAM:C COPY SYS:C/COPY RAM:C You could add to this series according to which commands you'd normally use. Now such a file requires the COPY command to be read from your disk each time, so we could add a further refinement by copying the COPY command directly to RAM:C first, and then ASSIGNing a short alias to it (ie, you give it a shorter name for convenience) , to speed up the processes of both executing the command and of typing it in, as follows: MAKEDIR RAM:C COPY SYS:C/COPY RAM:C ASSIGN CP: RAM:C/COPY CP: SYS:C/CD RAM:C CP: SYS:C/DIR RAM:C CP: SYS:C/TYPE RAM:C ASSIGN C: RAM:C A further refinement now could be to insert the line CD SYS:C after the first line above - this would make it unnecessary to type in the "SYS:C" before each command to be copied, since you'd already be in the directory that you're copying from. REMOVING A RAM DISK'S CONTENTS It may be that you've got to do some memory-intensive work, such as animations, and want to use all the memory you've got. You'll want to remove all those commands on the RAM disk, so you may make up a CSF like the following (and keep it in your S directory as usual): ECHO "CLEARING THE RAM DISK" CD DF0: ASSIGN C: SYS:C DELETE RAM:C ECHO "ALL DONE NOW" Here's another approach to achieving the same objective, except that this time, some more use has been made of the ASSIGN and ECHO commands. Note that you could also use the SAY command, so that you're told what's happening as it happens. COPY DF0:C/ECHO TO RAM:C COPY DF0:C/COPY TO RAM:C COPY DF0:C/ASSIGN TO RAM:C ASSIGN C: RAM:C ECHO "MAKING A RAM DISC" ECHO " " ECHO "COPYING SYS/C TO RAM" COPY SYS:C RAM:C ALL QUIET ECHO "" ECHO "ASSIGNED C: TO RAM:C" ECHO "" ECHO "ALL DONE NOW" In other words, it is up to you and what you want to achieve, and the best way of getting what you want is to experiment. 3. FURTHER CAPABILITIES OF BATCH FILES Although any CLI command can be used in a command file (including the command EXECUTE itself), certain commands were made especially for use in a command file (for futher information, see the listings in the COMMANDS drawer): IF these allow you to test conditions occurring during execution ELSE of the sequence, and to act on the results. ENDIF FAILAT sets the level of failure at which the sequence will stop. QUIT QUIT will force a stop with a return code you choose. SKIP allows you to mark areas (LAB) in your sequence and then jump LAB forward to them (SKIP). WAIT stops sequence processing for a period of time, or until a specified time of day. ECHO lets you display text strings, such as prompts, from within your sequence. ASK lets you branch either of two ways with a Y(ES) or N(O) PASSING INSTRUCTIONS TO BATCH FILES The EXECUTE Command itself recognises various DIRECTIVES, which allow you to pass words and substitute them in the various command lines in the CSF. Thus you can use one CSF for a variety of tasks if you design your CSF well. A "dot command" MUST be on the first line of the file. It can be any command, but is usually either a parameter template (.KEY) or a comment. .KEY or .K This defines the names of the parameters to be passed. This is the most important of the dot commands. If this is placed at the beginning of your CSF, then your CSF will take whatever file follows your CSF name and substitute it wherever it sees "filename1" in the batch file. EXAMPLE: .KEY filename1 COPY TO :MYDOCS To use this CSF (whose name is BACKUP, say), enter EXECUTE BACKUP Letter Now the file LETTER is copied to the MYDOCS directory on the current disk. .DEF defines a global default parameter value (the $ default is used on that line only) EXAMPLE: .DEF filename1 #?.doc If this were inserted in the above example, then if no specific filename were given, then #?.doc would be substituted for the filename, and all files of that pattern would be copied to the :MYDOCS directory. This gives you a failsafe option, since otherwise all files in the current directory would be acted upon. .DOT redefines the command indicator character (default is dot '.') EXAMPLE: .DOT @ then use @KEY from,to .BRA redefines the left & right parameter indicators .KET (default are '<' and '>') This can be useful if you want to include a name which has the current default bracket characters (ie, < & > ) EXAMPLE: .BRA [. This will change the left angle bracket character (<) to the the left square bracket character. Note the period after [ . .DOLLAR redefines the default indicator character (default is dollar '$') EXAMPLE: ED This substitutes "file", but if "file" is not given, will substitute "work.doc" . . indicates that the rest of the line is a comment. EXAMPLE: . Dot, followed by space is a comment. . indicates a blank comment line. FURTHER EXAMPLES The following sequence is used to delete a file, but make a backup first in the :T subdirectory. . Delete a file, but make a backup first . .KEY from,to IF "" EQ "" QUIT 20 ;this terminates the CSF immediately ENDIF IF "" EQ "" COPY TO :T/.Old DELETE QUIT ENDIF COPY TO :T/ DELETE QUIT This would be entered as follows (if the name of the CSF is BACKUP): EXECUTE BACKUP filename1,filename2 For further examples of batch files, see the DESCRIPTIONS of the various commands associated with this section, and the other tutorials on Batch Files/Startup-Sequences in this menu. ####################### END OF BATCH_FILES1 ######################