• Aucun résultat trouvé

programs to copy—it's already in RAM:, remember? Finally, '—'

Dans le document Lt QU (Page 72-76)

the D: device name is reassigned to the DELETE command.

64 ^—'

n

It's convenient to put shortcut assignments like this in the startup-sequence command file, since they let you type only two"characters whenever you want to use a common com mand like DELETE (D: oldfile works when you ASSIGN" D:

C:delete).

Another common task you can perform at startup time is setting the system clock and calendar. If you've purchased an optional hardware clock/calendar, it probably came with a program for setting the system clock from the hardware clock.

The command to run this program should be part of your startup-sequence file. If you don't have a hardware clock, you should set the time and date manually each time you start the system. The original startup-sequence file on your Workbench disk prints a message telling you to set the date and time from the Preferences program. If you prefer, you can give yourself the opportunity to set the time and date as part of your startup-sequence file. The following example demonstrates one technique for doing this:

ECHO " "

ECHO "The current setting of the date and time is:"

DATE ECHO " "

ECHO "Enter the correct date and/or time now."

ECHO "Use the form DD-MMM-YY for the date (format as 09-Sep-86)."

ECHO "Use the form HH:MM:SS or HH:MM for the time (format as 14:55)."

ECHO " "

The next command is tricky. It uses the question mark form of DATE to prompt you with the command template and wait for in put. It uses redirection to send the prompt text down a black hole.

The result is that it accepts input and sends it to DATE.

DATE > nil: ? ECHO " "

ECHO "The new date and time settings are:"

DATE

DATE >now

As the comments in italics explain, this example uses the question mark form of DATE. Normally, when you type DATE ?, the DATE command prints out its command tem plate and waits for you to enter input in that format. By

Command Sequence Files

redirecting the output of the command to NIL:, which does nothing with it, you suppress the command template and in stead provide more detailed instructions as reminders to your self. Redirecting the output to NIL: performs an additional function as well. If you decide that you don't want to change the date and just press RETURN, the DATE command doesn't get any instructions about what date or time is to be set. In such a case, the command normally prints out the current date or time. Here, that would be inappropriate and would confuse the display. Luckily, the redirection to NIL: prevents this text from being displayed so that if you just press RETURN, noth ing happens.

Notice that the last command in the new startup-sequence file redirects the output from DATE to the file now. This kind of date stamping can be helpful, for the Amiga looks to the most recently modified or created file to set the time (if you don't do it yourself manually). Thus, if you haven't altered or created any files since the last time you booted the computer up, it looks to now for the current date.

Passing Instructions to Commands

As convenient as it may be to EXECUTE a sequence of com mands stored in a file, it limits you to working with the same specific files and directories every time. That's why

AmigaDOS has a mechanism for passing words from the EXE CUTE command line to the command file and substituting them in the commands. This lets you create command files which do different things, depending on what you type in the EXECUTE command line.

Since this concept is much easier to demonstrate than to explain, let's take a very simple example. Suppose you want to create a command file which makes a backup copy of a file.

You need some way of specifying the name of the file so that you won't be continually backing up the same file. The following short command file, named Backup, does just this:

.KEY filename f.K filename is also acceptable) COPY <filename>TO :Backups

To use this command file, type EXECUTE Backup Mydata. The result is that the file named Mydata is copied to the Backups directory (this assumes that the Backups directory already exists in the root directory). If you typed EXECUTE

u

Command Sequence Files

Backup Program, the file named Program would be copied to Backups. The key to this process is in the first line of the file.

The line starts with the word .KEY, which is not a normal CLI command, but rather a directive which tells the EXECUTE command how to operate. The .KEY directive tells EXECUTE that the command template which follows should be used to determine what commands can be passed to this command file. In this case, .KEY tells EXECUTE that if a word is entered on the EXECUTE command line after Backup, that word is to be referred to as filename. Anytime <filename> appears in the Backup file, the word appearing on the command line after Backup is substituted. Thus, when you type EXECUTE Back up Mydata, EXECUTE takes the command line COPY <file-name> to -.Backups and substitutes Mydata everywhere that

<filename> appears. The result is the command line COPY Mydata TO -.Backups.

If you don't enter any command words after the name of the command sequence file, there's nothing to substitute for the keyword specified by the .KEY (or .K) directive. In the above example, the command EXECUTE Backup translates to the command line COPY TO -.Backups, which copies everything in the current directory to the Backups directory. This may not be the result you wanted. Fortunately, AmigaDOS provides a way to prevent this. It allows you to specify a default value to be substituted for the keyword if the user (yourself, more than likely) doesn't enter a substitution value. There are two ways of specifying the default value.

You can use the .DEF directive, followed by the substitu tion value. When you use this directive, the default value is substituted wherever the keyword appears in the absence of a normal substitution. Let's change the Backup command file to look like this:

.KEY filename

.DEF filename #?.*bas

ECHO "Copying <filename> to the Backups directory"

COPY <filename> TO :Backups

Now, if you type EXECUTE Backup, the pattern ex pression #?.bas is substituted for the keyword, and the com mand becomes COPY #?.bas TO '.Backups. The pattern matches any file whose name ends in the characters .has, so any file fit ting that description is copied to Backups. An ECHO command was added to tell you what's happening. The default value is

Command Sequence Files

Dans le document Lt QU (Page 72-76)