Caldera DR-DOS 7.02 User Guide

March 23, 2018 | Author: Huu Dinh Nguyen | Category: Command Line Interface, Computer File, File Format, Operating System, Software Engineering


Comments



Description

Caldera DR-DOS 7.02 User Guide 1 von 34 http://www.drdos.net/documentation/usergeng/07ugch7.htm#813 [Front] [Prev Chapter] [Next Chapter] Chapter 7 Batch Processing What is a Batch File Creating Batch Files with Edit Creating Batch Files with COPY Running Batch Files Stopping Batch Files Displaying Messages Using Replacement Variables Using Environment Variables Controlling Execution of Commands Using System Information Running a Batch File from Inside Another Batch File Command Reference What are Macros Creating Macros Using DOSKEY Editing Macros 13.04.2015 10:53 Caldera DR-DOS 7.02 User Guide 2 von 34 http://www.drdos.net/documentation/usergeng/07ugch7.htm#813 Running and Stopping Macros Saving Macros in Batch Files When you work with the operating system, you usually enter commands at the system prompt and the system executes them. This is referred to as interactive processing. There is another kind of processing, however, called batch processing. This chapter describes two methods of batch processing: batch files and macros. What is a Batch File? As you work with the operating system, you will probably find that you enter a command or a sequence of commands over and over again. You may have a set procedure each morning to load a spreadsheet program, for example, and another procedure in the evening to back up the files you created or changed during the day. Batch processing allows you to collect all the commands you need to carry out a task into a single batch file so that you do not need to enter each command individually. When you enter the name of the batch file at the system prompt, each command in the file is executed as if you had entered them one at a time. Using a batch file also ensures that a procedure is carried out in exactly the same way every time. For example, assume that you use the following commands every day to back up your files: CD \LETTERS <Enter> (to make LETTERS the current directory) ERASE *.OLD <Enter> (to erase all files with the extension .OLD) MD A:\DAYSWORK <Enter> (to create the directory DAYSWORK on the A: drive) 13.04.2015 10:53 Caldera DR-DOS 7.02 User Guide 3 von 34 http://www.drdos.net/documentation/usergeng/07ugch7.htm#813 COPY *.DOC A:\DAYSWORK <Enter> (to copy all files with the extension .DOC to A:\DAYSWORK) You can create a batch file that contains all of these commands called DAYOVER.BAT. Then, at the end of the day, you would only need to enter the following to execute all of the commands: DAYOVER Creating Batch Files with EDIT You can create batch files using EDIT or another word processor. NOTE: If you want to use a word processor other than EDIT, make sure that the completed batch file is in ASCII format. Refer to the word processor documentation for more information. The rules for naming a batch file are the same as for any other file except that you must use the extension .BAT. Also, you must enter each command in the batch file on a separate line. To create the batch file described in the previous section, for example, type the following at the system prompt: EDIT DAYOVER.BAT <Enter> Because this is a new file, you see a message asking you whether you want to create it. Press <OK> and the EDIT screen is displayed. Type the commands you want in the batch file, as follows, pressing <Enter> at the end of each line: CD \LETTERS ERASE *.OLD MD A:\DAYSWORK COPY *.DOC A:\DAYSWORK Press <Ctrl> KX to save the file and exit EDIT. 13.04.2015 10:53 Use the following version of COPY: COPY CON filespec When you specify CON as the device. every character you enter is recorded in the destination file you specify (filespec). "Editing Text Files" for complete information. such as <Enter> to start a new line or <Ctrl> H to delete the character to the left of the cursor.04. Example Assume you created the following batch file to copy two sets of files from 13.net/documentation/usergeng/07ugch7. See the sections "Command Line Editing" and "Extended Command Line Editing" in the "Command Reference" chapter of DOSBook for a complete list of the command line editing keys. When the batch file is finished executing. Refer to the description of PATH in the "Command Reference" chapter of DOSBook for more information about search paths. you do not need to include the extension (. the system prompt returns. Use this procedure to create any batch file you require.htm#813 NOTE:There are several other ways of saving files and quitting EDIT.2015 10:53 . Creating Batch Files with COPY Instead of using EDIT or another word processor. you can use the COPY command to create batch files directly at the system prompt. except for the line editing characters you use.BAT). Press <Ctrl> Z or <F6> when you have finished entering your file and close the file by pressing <Enter>. Refer to Chapter 6.02 User Guide 4 von 34 http://www. Run a batch file by entering its name in the command line. Running Batch Files To run a batch file. it must be located in the current directory or in one of the directories in the search path defined by PATH.drdos.Caldera DR-DOS 7. * A:\ PGM1. you might see something similar to the following at the system prompt as each command in the file is executed: CD \DIRA then COPY *.Caldera DR-DOS 7.EXE PGM2.EXE 3 File(s) copied then CD \DIRB then COPY *. CD \DIRA COPY *.DAT A:\ MON.net/documentation/usergeng/07ugch7.drdos.04.02 User Guide 5 von 34 http://www.htm#813 the current drive to the root directory of the diskette drive: all files in the directory DIRA and then all files with the extension .EXE PGM3.DAT in the directory DIRB.DAT 13.* A:\ CD \DIRB COPY *.2015 10:53 .DAT TUES.DAT WED.DAT A:\ CD\ When you run the batch file. net/documentation/usergeng/07ugch7.2015 10:53 . Refer to the descriptions of @ and ECHO in "Batch File Command Reference" starting on page 7-14. the commands contained in a batch file are displayed during batch file execution.Caldera DR-DOS 7. assume you include the following statements at the beginning of a batch file: @ECHO OFF 13. You return to the system prompt. that message displays regardless of whether the ECHO feature itself is set to ON or OFF.02 User Guide 6 von 34 http://www. Displaying Messages By default.DAT FRI. Answer N for NO and the remaining commands will be processed. To disable this feature.04.DAT 5 File(s) copied then CD\ Stopping Batch Files Press <Ctrl> C to stop a batch file while it is running. For example.htm#813 THURS. When you include a message preceded by ECHO in your batch file. set the ECHO command to OFF. You will see the following message: Halt Batch Process (Y/N)? Answer Y for YES and the remaining commands in the batch file are not executed. ECHO can also be used to display messages during batch file execution. Enter ECHO by itself at the system prompt to see the current status of ECHO.drdos. You can also prevent the display of individual commands in a batch file by preceding the command with @. you can make the batch file behave differently according to the parameters you enter with the filename when you run the file. any comments or remarks that you include in a batch file are also displayed. any line in a batch file that begins with REM is ignored during execution (other than being displayed when ECHO is ON). Generally speaking. you must enter it in the batch file as TEST%%. you must enter it twice. %2 represents the second parameter. %1 represents the first parameter at the system prompt.net/documentation/usergeng/07ugch7.Caldera DR-DOS 7. and so on. If you want to use the % character in a filename within a batch file.04.02 User Guide 7 von 34 http://www.DAT.htm#813 ECHO THIS IS MY FIRST ECHO BATCH FILE When you run the batch file. you must also use the SHIFT command in your batch file.drdos.2015 10:53 . always separate 13. where n is a number from 0 through 9. When you run the batch file at the system prompt.DAT. the following message is displayed: THIS IS MY FIRST BATCH FILE Comments When ECHO is ON. %3 the third parameter. the variables are replaced by the parameters entered at the system prompt. Using Replacement Variables By using replacement variables in a batch file. You include comments by using the REM command. If the filename is TEST%. for example. Refer to the description of SHIFT in "Batch File Command Reference" starting on page 7-14. Replacement variables are entered as %n. %0 represents the batch file name. you should not use the % character in filenames. If you want to use more than 10 parameters. SHIFT allows you to change the position of command line parameters by shifting them one parameter position to the left. When you run the batch file. if created in C:\AMANDA\LETTERS. you would type the following: MOVEOVER SMITH.BAT to copy and delete a file called JONES.02 User Guide 8 von 34 http://www. copies any file from C:\AMANDA\LETTERS to C:\QUERIES\DONEWITH and then deletes the original: COPY %1 C:\QUERIES\DONEWITH ERASE %1 So to run MOVEOVER.BAT. Environment variables are similar to replacement variables except that they are not provided in the command line that runs the batch file.LET instead.Caldera DR-DOS 7. and some are handled by the SET command.2015 10:53 .LET. 13.LET C:\QUERIES\DONEWITH ERASE JONES. Some are pre-defined by the operating system.LET <Enter> Using Environment Variables You can also use environment variables in batch files. you would simply type the following: MOVEOVER JONES.LET To copy and delete SMITH. Example The following batch file MOVEOVER.LET <Enter> The operating system would then execute the following commands: COPY JONES. Table 7-1 lists the standard environment variables. some are set by specific commands.drdos.04.net/documentation/usergeng/07ugch7. Refer to the description of SET in the "Command Reference" chapter of DOSBook for information about SET.htm#813 parameters with a space and make sure that they are entered in the correct sequence. 02 User Guide 9 von 34 http://www.net/documentation/usergeng/07ugch7. PEXEC Used by the PROMPT command.2015 10:53 . the following command changes the current system prompt: PROMPT %OS% $P$G <Enter> Controlling Execution of Commands Most batch files are more than just commands and variables. 13. PATH The current PATH search path. To use the current value of an environment variable in a batch file.htm#813 Table 7-1 Environment Variables Variable Name Function APPEND The current APPEND search path. DRDOSCFG The directory containing the system configuration files. For example.04. VER The current operating system version. COMSPEC The location on disk of the command interpreter. You can also use various special batch file subcommands to control the flow of execution within a batch file and perform more complex tasks.Caldera DR-DOS 7.drdos. TEMP The directory used to hold temporary files. OS The current operating system name. PROMPT The current system prompt. enclose it in % signs. when execution reaches the GOTO statement in the following lines.BAT to start a certain computer game when you type the following command: GAME FUN <Enter> You could include the following statement in GAME. the operating system skips the PLAY command and processes the next line in the batch file.2015 10:53 .04.drdos. and a GOTO command.02 User Guide http://www. to identify a particular point within the file.Caldera DR-DOS 7. it is forced to jump back to the label START and continue processing from there. If %1 is not FUN. You can specify that one string must equal another. :START TYPE INFO.Example of Using GOTOs GOTO LABEL1 10 von 34 13.htm#813 Conditional Execution Use the IF statement to specify a condition that must be true before a command is run. You do this by using a label. the next line of the batch file is processed. Assume that you want to create a batch file called GAME.BAT . @ECHO OFF REM GOTO. For example.net/documentation/usergeng/07ugch7.BAT so that the game is started only if %1 (the first parameter in the command line) is FUN. for example. IF "%1" == "FUN" PLAY After PLAY is finished.TXT GOTO START The next example shows a batch file with three GOTOs in it. Changing Execution Flow You can also force processing of a batch file to switch to another part of the file and continue executing commands from that point. 02 User Guide http://www.drdos. Statements are processed until a RETURN command is encountered.Caldera DR-DOS 7. The value such a command returns can be tested using an IF ERRORLEVEL command. for example. tests the return code from an XCOPY operation: XCOPY %1 %2 IF ERRORLEVEL 1 GOTO FAIL DEL %1 11 von 34 13. Many external commands set a return code or "error level" when they finish. Using IF and GOTO Together By using GOSUB or GOTO commands together with IF statements. The following batch file.2015 10:53 .net/documentation/usergeng/07ugch7.htm#813 REM This part is never executed ECHO This part is never executed :LABEL2 ECHO The program is at LABEL2 GOTO END REM This part is executed first :LABEL1 ECHO The program is at LABEL1 GOTO LABEL2 REM This part is executed last :END ECHO This is the end of the file You can use GOSUB instead of GOTO when you want to force execution to a subroutine rather than an individual command. you can run different sections of the batch file according to different conditions.04. Using System Information You can use a number of "system information" values in a batch file. for displaying extra information or for testing to determine the way in which the batch file executes. and GOSUB in "Batch File Command Reference" starting on page 7-14 for more information about using these commands to control batch file execution.02 User Guide http://www.Load EMS ECHO driver GOTO END :OK CALC :END Refer to the descriptions of IF. The following batch file. uses IF to test whether expanded memory is available before starting a calculator application called CALC: IF EXIST EMMXXXX0 GOTO OK ECHO EMS memory manager not loaded . 12 von 34 13.Not Deleting Files :END You can also specify that a certain file or condition must exist or must be true before a command is executed. however.drdos.htm#813 GOTO END :FAIL ECHO Copy Failed . These values are like environment variables but in most cases you cannot set their values yourself. All the system information variables are listed in Table 7-2. for example.net/documentation/usergeng/07ugch7.04. GOTO.Caldera DR-DOS 7.2015 10:53 . They are useful. Short_Year 83. 2016.Caldera DR-DOS 7.drdos. etc. 95. Hour24 00 to 23 Minute 00 to 59 Second 00 to 59 Greeting_Time Morning. Year 1983. Day 01 to 31 Day_of_Week Monday. Tuesday.htm#813 Table 7-2 System Information Variables Variable Name Explanation AM_PM a. Hour 1 to 12 NDay_of_Week 1 to 7 (1=Sunday) Month 01 to 12 Month_Name May.02 User Guide http://www.m.net/documentation/usergeng/07ugch7. or p.2015 10:53 .04.m. Afternoon. etc. or Evening ErrorLevel Error return code OS Operating system (DRDOS) OS_Version Operating system version number The following variables are only available when you have the NetWare® 13 von 34 13. etc. June. December. etc. ECHO "Good %Greeting_Time% %Login_Name%" IF NOT "%Login_Name%" == "FRED" GOTO NOMAIL ECHO "Checking Mail" .drdos. The remaining statements in the original batch file are not executed. :NOMAIL Running a Batch File from Inside Another If you want to run a batch file from inside another batch file. you return to the system prompt. for example. simply include the name of the second batch file inside the first. cause the appropriate greeting (including the greeting time and login name) to display for any user. When it has finished running.04. however. The second batch file is run when the operating system processes the line containing the name of the file... if the user is FRED.2015 10:53 . Mail will only be checked.net/documentation/usergeng/07ugch7. .02 User Guide http://www. To run a batch file from inside another and then return to the original batch 14 von 34 13.Caldera DR-DOS 7..htm#813 drivers and shell loaded: Table 7-3 System Information Variables (NetWare) Variable Name Explanation Login_Name User's login name P_Station Physical station number Station Station number The following statements in a batch file.. This section describes each of these commands. CHOICE is an external command that is only used in batch files. however. Refer to the "Command Reference" chapter of DOSBook for descriptions of all these commands.drdos. Refer to the description of CALL in "Batch File Command Reference" starting on this page for more information. INNER.BAT You can call as many batch files as you like from inside another batch file. NOTE: All batch file subcommands (except CHOICE) are internal commands. displays a message and then calls another batch file. using the same syntax as you would use when entering the command at the system prompt.net/documentation/usergeng/07ugch7.BAT.htm#813 file and continue processing. 15 von 34 13. you can use the CALL command in the original file.2015 10:53 .02 User Guide http://www. Batch file subcommands allow you to write batch files that are like simple programs. for example. execution returns to OUTER. As described previously in this chapter.Caldera DR-DOS 7. Batch File Command Reference Any command you enter at the system prompt can be used in a batch file. The conventions used in the following command descriptions are the same as those used in the "Command Reference" chapter in DOSBook.BAT and processes the next line (which displays another message): @ECHO OFF REM OUTER. The following batch file OUTER. there are also special commands available for use with batch files called batch file subcommands. refer to this if you need an explanation of the conventions.BAT.BAT is finished.04.BAT CALL INNER ECHO I am back in OUTER.BAT ECHO I am in OUTER. When INNER. You can also specify the text of the prompt by including it between the question mark (?) and the beginning of the statement.net/documentation/usergeng/07ugch7. Note that the maximum length of a batch file statement (including ?) is 128 characters. a response to the prompt is required by the user before processing continues. 16 von 34 13. When you run a batch file containing a ? statement. Example The following line in a batch file turns the ECHO feature off and ECHO OFF itself is not displayed: @ECHO OFF ? Format ? ["message_string"] command Explanation The question mark (?) at the beginning of a statement causes the operating system to prompt the user about whether the statement should be processed.drdos.04.Caldera DR-DOS 7. enclosed by double quotation marks.htm#813 @ Format @ command Explanation @ prevents the specified command from displaying during batch file execution.2015 10:53 .02 User Guide http://www. or SWITCH command within the same file.net/documentation/usergeng/07ugch7. when the file executes. GOTO.OLD So.OLD from C:\ACCOUNTS: ?DEL C:\ACCOUNTS\*.OLD (Y/N) ? If the user answers Y. Only the first eight characters in a label are recognized.2015 10:53 .drdos. any additional characters are ignored.htm#813 Example The following statement in a batch file causes the system to prompt the user before deleting all the files with the extension .Caldera DR-DOS 7. the user sees the following: DEL C:\ACCOUNTS\*. the command is ignored and the next line in the batch file is processed. If the user answers N. :label Format :label Explanation A label defines a point within a batch file that can be referenced by a GOSUB. Labels are not displayed during batch file execution.04. the DEL command is run and the files are deleted.02 User Guide http://www. CALL Format CALL filespec Explanation 17 von 34 13. Caldera DR-DOS 7. The user selects from the displayed choices by pressing a key.04.02 User Guide http://www.2015 10:53 . /C:choices Specifies the keys that the user can select from.net/documentation/usergeng/07ugch7. to control what the batch file does next. such as IF. NOTE: CHOICE is an external command that is only used in batch files and is therefore described here rather than in the "Command Reference" chapter of DOSBook. Example The following batch file uses two CALLs to other batch files: REM This file runs BATCH2 and then BATCH3 CALL BATCH2 CALL BATCH3 CHOICE Format CHOICE [/C:choices] [/N] [/S] [/T[:]c.htm#813 CALL runs another batch file before the next statement in the original batch file is processed. 18 von 34 Command Switches /? or /H Displays help text.nn] [text] Explanation The CHOICE command is used in batch files to present the user with choices. and CHOICE returns an ERRORLEVEL value that reflects the key pressed. The search path defined by the PATH command is used to locate the second batch file. The ERRORLEVEL value can be used by other batch file commands. choices can be any keys that can be used on a command line except 13.drdos. and /. nn can be in the range 0-99 but if nn is 0. CHOICE displays these key choices after any prompt text specified in the CHOICE command.N.Caldera DR-DOS 7. or Exit [Y. CHOICE displays [Y.2015 10:53 .htm#813 <Space>. the /T switch is ignored.N]?. /S Specifies that the choice keys are case-sensitive. and help text is displayed.drdos. c must be Y (for Yes) or N (for No). and 19 von 34 13. or Exit the user sees the following message when the batch file runs: Yes.E] CHOICE returns ERRORLEVEL 1 if the user presses Y.net/documentation/usergeng/07ugch7.04. 2 if they press N. ERRORLEVEL 2 if the user selects the second of the keys. If you do not specify the /C switch. If choices are not specified. No. <Tab>. /N Disables the display of the choice keys and the question mark after the prompt text. Examples If you include the following command in a batch file: CHOICE /C:yne Yes. By default.nn Specifies that CHOICE defaults to key c after nn seconds unless the user makes a selection before then. ERRORLEVEL 255 is returned. CHOICE returns 0. and so on. The text must not include a forward slash (/). If the user presses <Ctrl> C instead of selecting one of the keys.02 User Guide http://www. CHOICE returns ERRORLEVEL 1 if the user selects the first of the key choices. text Specifies the prompt text that precedes the key choices displayed to the user. c must be one of the characters specified by the /C switch. /T:c. No. If the user enters an invalid CHOICE command. the user is given the option to select one of three utilities: DOSBook. @echo off :start cls echo DOSBOOK echo EDIT echo SETUP echo ------choice /c:desq Select an option or Q to quit if errorlevel 4 goto end if errorlevel 3 goto setup if errorlevel 2 goto edit if errorlevel 1 goto dbook :setup setup goto start :edit edit 20 von 34 13.10 Yes. or SETUP.04. EDIT. In this example.drdos.2015 10:53 . or Exit The next example demonstrates how CHOICE can be used in conjunction with other batch file commands.htm#813 3 if they press E. unless the user makes a selection within 10 seconds: CHOICE /C:yne /T:y.Caldera DR-DOS 7. In the following example CHOICE defaults to Y.02 User Guide http://www. No.net/documentation/usergeng/07ugch7. 04. the batch file would always jump to DOSBook. Use multiple ECHO statements to display more than one line of message text. enter ECHO without a parameter. ECHO is ON by default.htm#813 goto start :dbook dosbook goto start :end cls NOTE: The IF statements in this example are true if the ERRORLEVEL value returned by CHOICE is greater than. or equal to.Caldera DR-DOS 7. To display the current status of ECHO.net/documentation/usergeng/07ugch7. a blank line appears when you run the batch file. the ERRORLEVEL specified in the IF statement. FOR 21 von 34 13. Therefore.2015 10:53 .02 User Guide http://www. including ECHO OFF itself. If you type a period immediately after ECHO in a batch file. ECHO Format ECHO [ON|OFF|message] Explanation ECHO enables or disables the display of commands during batch file execution when you specify ON or OFF. NOTE: @ECHO OFF is often used at the beginning of a batch file to prevent all commands from being displayed. if the order was reversed.drdos. the IF statements are listed with the highest ERRORLEVEL first. ECHO displays a message during batch file execution when you specify ECHO message. and then go back to the line immediately after GOSUB and continue processing from there.2015 10:53 . TYPE INTRO. You must use a RETURN with GOSUB. process commands until RETURN is found.TXT GOSUB LISTS CALL SUMMARY 22 von 34 13. Example The following statement in a batch file types two files to the screen in turn: FOR %%f IN (ACCT.BAS) DO TYPE %%f GOSUB Format GOSUB label Explanation GOSUB causes batch file execution to jump to the specified label. each filename is substituted for the command.BAS ACCT2.net/documentation/usergeng/07ugch7.Caldera DR-DOS 7. You can use wildcards in filenames. all matching filenames on the current drive will be substituted. Example The following batch file types a text file to the screen and then runs a subroutine to type three more text files before calling a second batch file.htm#813 Format FOR %%variable IN (fileset) DO command Explanation FOR executes the specified command for each file in a set of files.04.02 User Guide http://www. In sequence.drdos. Example The following batch file displays a file called INFO.TXT GOTO START IF 23 von 34 13. you see the following error message: Label xxxxxxxx not found Note that only the first eight characters of a label are recognized. If the label is not found. :START TYPE INFO.04. You must include the label referenced by a GOTO.drdos.htm#813 EXIT :LISTS TYPE LISTA.02 User Guide http://www.TXT RETURN GOTO Format GOTO label Explanation GOTO causes batch file execution to jump to the specified label and continue from there.TXT over and over again until you stop the file by pressing <Ctrl> C or <Ctrl><Break>.Caldera DR-DOS 7.TXT TYPE LISTB.TXT TYPE LISTC.net/documentation/usergeng/07ugch7.2015 10:53 . EXIST filespec This condition is true when filespec exists. The conditions can be any of the following: ERRORLEVEL n This condition is true when the error code produced by the previous program is greater than or equal to n (where n is a number).04.htm#813 Format IF [NOT] condition1 [OR [NOT] condition2] [AND [NOT] condition3] command Explanation IF specifies conditional execution of commands within a batch file. When the condition is not true (or true. for example). in the specified directory or in the current directory (if no dirpath is specified in dirpath). The command is executed when the condition is true.Caldera DR-DOS 7.net/documentation/usergeng/07ugch7. DIREXIST dirpath This condition is true when dirpath exists. in the specified directory or in the current directory (if no dirpath is specified in filespec).02 User Guide http://www. string1 =|==|!=|<> string2 This condition is true when the relationship between the specified string (string1) and another string (string2) matches the specified symbol: "identical to" (= or ==) or "not identical to" (!= or <>). Strings can be literal strings or batch variables (%hour%. command is ignored and the next statement in the batch file is executed.drdos.2015 10:53 . #value1 =|==|!=|<> #value2 This condition is true when the relationship between the absolute value of the specified variables matches the specified symbol. if you specify IF NOT). Examples 24 von 34 13. not deleting files :END The following IF statement specifies that WHERE IS JOHN? displays only if JOHN is not the current value of the %1 parameter.drdos. Note that the strings 25 von 34 13.not deleting files GOTO END :FAIL5 ECHO Disk write failure .htm#813 The following batch file uses several IF statements to test the ERRORLEVEL from an XCOPY operation: REM XCOPY and DEL with ERRORLEVEL Testing XCOPY %1 %2 IF ERRORLEVEL 5 GOTO FAIL5 IF ERRORLEVEL 4 GOTO FAIL4 IF ERRORLEVEL 3 GOTO FAIL2 IF ERRORLEVEL 2 GOTO FAIL1 DEL %1 GOTO END :FAIL1 ECHO Files %1 not found .not deleting files GOTO END :FAIL4 ECHO Could not start XCOPY .02 User Guide http://www.2015 10:53 .not deleting files GOTO END :FAIL2 ECHO Aborted .04.Caldera DR-DOS 7.net/documentation/usergeng/07ugch7. . 26 von 34 13. . this is optional.02 User Guide http://www. :XYZ . especially when no parameters are specified: IF "%1"<>"JOHN" ECHO WHERE IS JOHN? The IF statement in the following set of statements means that the commands between DIR B: and the label XYZ will only be executed if MYFILE does not exist in the current directory: IF EXIST MYFILE GOTO XYZ DIR B: . such as changing diskettes. . you should always use quotation marks around strings to prevent syntax errors. PAUSE Format PAUSE [remark] Explanation PAUSE delays batch file processing so that an action can be performed. You can specify an additional remark of up to 122 characters.04.Caldera DR-DOS 7. .htm#813 are enclosed by quotation marks. PAUSE always displays the following message: Strike a key when ready .drdos.2015 10:53 .net/documentation/usergeng/07ugch7. however. spaces. Any line in a batch file preceded by REM or a semi-colon is not processed.* B: When this batch file runs.2015 10:53 . REM Format REM | . the files on the diskette in the A: drive are copied to the diskette in the B: drive.Caldera DR-DOS 7. REM lines will be displayed on the screen as the batch file executes. You can use commas. NOTE: If ECHO is ON. Processing is then suspended and the following message appears on the screen: Insert new disk in DRIVE A: Strike a key when ready . Empty comment lines (REM with no remark) are useful for adding space to a batch file. 27 von 34 13. making it easier to read and edit.net/documentation/usergeng/07ugch7.04.htm#813 Example The following batch file includes a PAUSE command with a remark specified: COPY A:*.drdos. and tabs to separate words.02 User Guide http://www. .) causes the operating system to treat a statement as a comment or remark. The maximum length of remark is 123 characters. You can either insert a new diskette and press any key to continue or press <Ctrl> C to stop batch file processing. . [remark] Explanation REM or a semi-colon (.* B: @ECHO OFF PAUSE Insert new disk in DRIVE A: COPY A:*. SHIFT Format SHIFT Explanation SHIFT allows you to access more than nine command line parameters (%1 to %9) by shifting their position to the left. When SHIFT is executed. the value in %0 is replaced by the value in %1. SHIFT simply moves the window one position to the right. which is replaced by the value of %9. The batch file COPYX.htm#813 RETURN Format RETURN Explanation RETURN causes batch file execution to return to sequential processing of commands after a GOSUB or SWITCH statement. is designed to copy a number of files to a single destination directory. for example. Think of the batch parameters as a "window".2015 10:53 .net/documentation/usergeng/07ugch7. %1 is replaced by %2. Use SHIFT as many times as you need to get all of the parameters in the command line. you would enter the following to run COPYX: 28 von 34 13. %2 by %3.02 User Guide http://www.drdos. Example SHIFT is most useful when you are using a batch file to perform a single operation many times and using a varying number of command line parameters. and so on up to %8.Caldera DR-DOS 7.04. up to a maximum of 10 at a time. Caldera DR-DOS 7..htm#813 COPYX filename1 filename2 filename3. dirpath COPYX. SHIFT REM Go back to look at the rest of the REM parameters GOTO LOOP :NO_MORE_FILES REM The first parameter now contains the 29 von 34 13.drdos..BAT would be written as follows: @ECHO OFF IF "%1" == "/?" GOTO HELP REM COPYX requires at least 2 parameters if REM the first parameter is not /? IF "%2" == "" GOTO FAIL SET COPYX_FILE = :LOOP REM If the second parameter is empty.net/documentation/usergeng/07ugch7. add the first parameter to the REM list of files to copy SET COPYX_FILE = %COPYX_FILE% %1 REM Now SHIFT the parameters so that %1 is REM replaced by %2.2015 10:53 .02 User Guide http://www. the REM first parameter must be the destination IF "%2" == "" GOTO NO_MORE_FILES REM Otherwise. etc.04. .. SWITCH creates a simple menu interface.2015 10:53 .net/documentation/usergeng/07ugch7.02 User Guide http://www.. dirpath GOTO END :END SET COPYX_FILE = SWITCH Format SWITCH label1. label3.. label2[. In effect. When the label is entered.htm#813 REM destination REM COPYX_FILE contains the list of files to REM copy FOR %%i IN (%COPYX_FILE%) DO XCOPY %%i %1 GOTO END :FAIL ECHO COPYX: At least 2 parameters are required GOTO END :HELP ECHO COPYX: Multiple file copy program ECHO Enter: COPYX filename1 filename2. depending on the information (label) provided by the user.drdos.Caldera DR-DOS 7. execution jumps to that label in the batch file and returns to the line following SWITCH when a RETURN command is 30 von 34 13. label9] Explanation SWITCH causes batch file processing to switch between several different subroutines within the same batch file.04. SWITCH also causes the batch file to prompt the user for this information. 04.drdos.net/documentation/usergeng/07ugch7. DB.htm#813 encountered. The maximum number of labels you can use in a SWITCH command is nine. EX GOTO BEGIN :WP EDIT RETURN :VP CALL VPPROF RETURN 31 von 34 13.Caldera DR-DOS 7.02 User Guide http://www. VP. Example The following batch file defines a SWITCH routine for selecting an application from a list of applications: @ECHO OFF :BEGIN CLS ECHO APPLICATIONS MENU ECHO ================= ECHO 1 Word Processor ECHO 2 Desktop Publisher ECHO 3 Database ECHO 4 Exit ECHO Choose a number from 1 to 4 SWITCH WP.2015 10:53 . Caldera DR-DOS 7. it consists of a number of commands that you execute by entering a single name at the system prompt. This means that they run faster than batch files. all the commands in a macro must be on the same line. The following sections in this chapter. Creating Macros Using DOSKEY The operating system provides the DOSKEY command to work with macros. for example. describe further differences between batch files and macros.drdos.04. simply type the DOSKEY command at the system prompt as follows: DOSKEY macroname = commands <Enter> The number of commands you can put in a macro is limited by the length of a single line (127 characters).htm#813 :DB CD \DATABASE DB RETURN :EX What are Macros? A macro is similar to a batch file. Macros use memory that would normally be used by command line HISTORY information.2015 10:53 . To create a macro.net/documentation/usergeng/07ugch7. The main difference between batch files and macros is that macros are stored in RAM rather than on disk and can be run from any directory. macros are lost when you reboot your computer. however. The following command line. Separate each command with $T (or $t).02 User Guide http://www. Also. about using macros.TXT files in the current directory in order of size before copying them to the root directory of the A: drive: 32 von 34 13. defines a macro that lists all the . Replacement variables are $1 through $9 in macros instead of %1 through %9 as in batch files. however. $B (or $b) Equivalent to the piping symbol (|). $G$G (or $g$g) Equivalent to the double greater-than sign (>>). You can define an environment variable in a macro using SET but you cannot use any environment variables in the macro itself.net/documentation/usergeng/07ugch7. Note the following restrictions about what you can use in macros: You cannot use GOTO commands in macros or start a macro from inside another macro. You can run a batch file from inside a macro.02 User Guide http://www.TXT A:\ Besides $t. Running and Stopping Macros To run a macro. press <Ctrl> C. followed by any parameters required. Editing Macros You edit a macro by editing the command line you entered to create it. This stops the command that is currently 33 von 34 13. enter its name at the system prompt.htm#813 DOSKEY CPYTXT = XDIR *. and then re-enter it. They are listed in the following table. Make sure you leave a space between the macro name and the parameters. Use the command line HISTORY feature to recall the command line. edit it. To stop a macro. $G (or $g) Equivalent to the greater-than sign (>).TXT /Z $t COPY *. Special Character Meaning $L (or $l) Equivalent to the less-than sign (<).04. there are other special characters you can use in a macro.2015 10:53 .Caldera DR-DOS 7.drdos. To save macros this way.net/documentation/usergeng/07ugch7. Inc. The following command. 1998 Caldera. stores all the macros currently stored in memory in a batch file called MACROS.2015 10:53 . [Front] [Prev Chapter] [Next Chapter] [email protected]. use the DOSKEY command with the /macros option and a redirection symbol.BAT: DOSKEY /MACROS >MACROS.htm#813 executing. All rights reserved.com Copyright © 1993.02 User Guide http://www. 1997.04. Saving Macros in Batch Files The best way of saving your macros is to put the commands into a single batch file and then run the batch file whenever you want to make the macros available. 34 von 34 13. Press <Ctrl> C as many times as necessary to stop every command in the macro. for example.Caldera DR-DOS 7.BAT Saving macros in batch files also means you can edit them in the future.
Copyright © 2024 DOKUMEN.SITE Inc.