Taming the Command Line with DOSKEY Ken Johnson, Chicago Computer Society This month's column will looks at one of the more interesting and exciting features of DOS 5.0 -- DOSKEY. Because of the hoopla over DOS 5.0's memory management, undelete and unformat recovery programs, improved Shell and QBasic, DOSKEY is easily overlooked. But, if you have upgraded to DOS 5.0, you owe it to yourself to give DOSKEY a spin. So what does DOSKEY have to offer? It significantly improves the (infamous) DOS command line by adding two major features: * A friendly DOS command line which allows you to recall and easily edit past commands. All commands you enter are stored in a memory buffer called the command stack. Besides recalling commands from the stack, you can search for and recall command(s) that match a text string you specify. Editing commands is now easier, both moving the cursor and inserting and deleting text. DOSKEY also will let you execute multiple DOS commands on one line. * The ability to create command macros. These macros allow you to modify the existing DOS commands and create custom "commands". Want to make the DEL command always prompt you before deleting a file? DOSKEY can change what happens when you type in DEL. Want to create your own "Find File" command to search your entire hard drive to find a file? DOSKEY can create such a command for you. We'll look at the command line usage (command recall and editing) this month, and focus on DOSKEY command macros in another article. Installing DOSKEY DOSKEY.COM is a TSR (Terminate and Stay Resident) program that has to be loaded into memory before it can be used. You can load DOSKEY directly from the command line, but you'll probably want to load it automatically whenever you boot up. It only takes up about 4K of RAM, and it's well work the space. You can load DOSKEY with the INSTALL command in CONFIG.SYS, or in your AUTOEXEC.BAT file. If you have a 386 processor, use the LOADHIGH command in AUTOEXEC.BAT to load DOSKEY into the upper memory area between 640K and 1 meg. The command syntax for DOSKEY is: DOSKEY [BUFSIZE=n] [/INSERT or /OVERSTRIKE] [/REINSTALL] [/MACROS] [/HISTORY] [macroname=commands] /BUFSIZE=n specifies the size of the DOSKEY buffer (the command stack). The default size is 512 bytes. If the command stack fills up, the oldest commands are pushed off the stack. But, you can run out of space for storing command macros. If you plan to create many macros you'll probably want to increase the buffer to 1024 or 2048 bytes. /INSERT or /OVERSTRIKE selects the default editing mode for the command line. The default is Overstrike. You can easily change to and from Insert and Overstrike by pressing the Ins key; but whenever you press Enter DOSKEY goes back to the default editing mode. When in Insert mode the cursor will change from an underline to a block. /REINSTALL installs a new copy of DOSKEY, even if it is already loaded in memory. This allows you, for example, to change the buffer size without rebooting the computer. Unfortunately the old copy of DOSKEY stays in memory, occupying about 4K of RAM that won't be unavailable for other programs. /MACROS (or /M) displays the currently defined macros. You use this switch to save your macros in a text file for use the next time you boot up your computer. (We'll see the use of this switch in next month's column). /HISTORY (or /H) displays all commands in the command stack. macroname=commands creates a macro. "Macroname" is the name of the macro; "commands" are the DOS commands you want to execute when you enter "macroname" at the prompt. You enter the "macroname=" without the "commands", the macro is deleted from the buffer. Using DOSKEY for Command Recall Once you have DOSKEY installed, all commands that you issue from the DOS prompt are stored (in order) in the command stack. You can then recall these commands in order or pick a specific command out of the list. You also can easily edit the commands once they're recalled. Let's say for example that you boot up your computer, check your memory configuration, copy a file from A: to C:, call the CCS BBS and download a file, unzip the file, and look at the documentation. Your commands might look like this in the buffer: mem /c | more cls copy a:customer.db c:\pdox35\pdoxdata ccsbbs pkunzip c:\pcplustd\download\drwatsn.zip a: dir a: edit a:readme.1st Now from the DOS prompt, press the Up Arrow. The last command you typed ("edit a:readme.1st") is redisplayed. If you continue to press the Up Arrow the commands will scroll backward through the stack. Similarly, the Down Arrow will cycle forward through the stack. If you want to execute one of the commands, simply press Enter when it is displayed. If you decide you don't want any of the previous commands, just press Escape to clear the command line. (Without DOSKEY installed, the Escape key moves the cursor to the next line). There are several other ways to recall past commands. To recall the oldest command, press PgUp. In our example, that would recall the "mem /c | more" command. As you might expect, the PgDn key recalls the most recent command. If you want to see all commands in the buffer, type in DOSKEY /HISTORY. Unfortunately, as the number of commands increase in the buffer, it becomes harder to find the specific command you need. Luckily DOSKEY helps with the F7, F8, and F9 function keys. When you press F7, you'll see a numbered list of commands in the buffer (it's the same display as DOSKEY /HISTORY, but with line numbers). If you've been moving through the buffer with the arrow keys, the current command will be marked with a greater- than sign ">". Our command stack would look like this when we press F7: 1: mem /c | more 2: cls 3: copy a:customer.db c:\pdox35\pdoxdata 4: ccsbbs 5: pkunzip c:\pcplustd\download\drwatsn.zip a: 6: dir a: 7: edit a:readme.1st You now can use the F9 key to recall a command by number. When you press F9, you'll be prompted with "Line number: ". Simply type in the line number and press Enter, and that command will be displayed. Now press Enter again to execute the command. If we wanted to call the CCS BBS again (using the CCSBBS.BAT file), enter line number 4 to recall the "ccsbbs" command. One of DOSKEY's real joys is the F8 key, which does a "smart search" of the command stack. You type in some text on the command line and press F8. DOSKEY will search backward in the command stack for the first command that starts with the text that you've entered. We could easily get back the "ccsbbs" command by typing "ccs" on the command line and pressing F8. If there is more than one command in the stack that matches what you entered, you can cycle through the matches (most recent to oldest) by continuing to press F8. There is no way to delete a specific command from the command stack, but you can delete ALL commands with the Alt-F7 key. This leads to an interesting feature of DOSKEY: using it to write batch files by recording your commands, then writing them out to a file. Here's how to do it: 1. Press Alt-F7 to clear the command stack. 2. Enter the DOS commands you want to record. 3. Press F7 to look at the commands. If they look good, then save them to a file by entering: DOSKEY /HISTORY >batname.BAT, where "batname.BAT" is the name of the batch file you want to create. The ">" symbol here is DOS' redirection symbol, which will write the DOSKEY /HISTORY output to the file. 4. You can now run the batch file by simply typing it's name. To review, here are DOSKEY's Command Recall keys: Up Arrow -- Recalls the prior command in the command stack. Down Arrow -- Recalls the next command in the command stack. PgUp -- Recalls the first command in the command stack. PgDn -- Recalls the last command in the command stack. F7 -- Displays a numbered list of the commands in the command stack, with "1" being the first (oldest) command in the stack. You can recall a command by pressing the F9 key and entering the desired number. Alt-F7 -- Clears the command stack; all commands are deleted from the buffer and are no longer available. F8 -- Recalls the prior command in the stack that matches what you've typed on the command line. Continue to press F8 to cycle through all the commands that start with those characters. F9 -- Prompts you for a line number and recalls the command with that number. Use F7 first to get the numbered commands, then F9 to recall that command. Escape -- Clears the command line. Editing Text on the Command Line Another great feature of DOSKEY is the improved command line editing it provides. Previous versions of DOS had limited editing capabilities with the function keys F1 to F5. Using these function keys was very crude, since they basically copied characters from one previous command (an invisible thing called the "template") to the command line. DOSKEY has significantly eased editing the command line. DOSKEY's cursor movement keys are nondestructive, meaning that they don't delete characters as they move. You can easily position the cursor in the right spot and then add, delete, or change text as necessary. DOSKEY's editing keys include: Left Arrow -- move the cursor one character to the left. Right Arrow -- move the cursor one character to the right. Ctrl-Left -- move the cursor one word to the left. Ctrl-Right -- move the cursor one word to the right. Home -- move the cursor to the beginning of the line. End -- move the cursor to the end of the line. Del -- deletes the character at the cursor. Backspace -- deletes the character to the left of the cursor. Ctrl-Home -- deletes all text from the character to the left of the cursor to the beginning of the line. Ctrl-End -- deletes all text from the cursor to the end of the line. Escape -- clears the command line (deletes everything). A final editing feature of DOSKEY is the ability to execute multiple commands on one line. You do this by separating the commands with a Ctrl-T, which shows up on the screen as a paragraph mark (). You can combine as many commands as you want as long you don't exceed 127 characters (the size limit of the command line). Let's say you wanted to copy a file called JUNK.TXT from the C: drive to the A: drive, then delete the original file. You could enter: copy c:junk.txt a:  del c:junk.txt Remember that the  symbol is entered by pressing the Ctrl-T combination. As you can see, DOSKEY brings a more user-friendly command line to DOS 5.0. The command stacking and ease of editing make it well worth the 4K of RAM. But this is only part of what DOSKEY has to offer. The real power of DOSKEY is in its ability to create command macros. With command macros you can improve your efficiency, create new DOS "commands", and modify existing DOS commands to make them simpler or safer. In next month's Beginners Column we'll look at DOSKEY command macros, and provide several examples that you can immediately put to work. As a final note, if you don't have DOS 5.0 (and why not?!), there are utility programs that can provide you with the same capabilities as DOSKEY. Three such shareware programs are: CED, written by Chris Dunford. CED provides easier command line editing, the ability to retrieve commands from a command stack, command parameter recall, and creation of synonyms for DOS commands (similar to DOSKEY macros). CED is also available in a commercial version. DOSKEY, written by Jeff Prosise of PC Magazine. DOSKEY allows you to change screen colors with function keys, recall up to the last 15 commands from a buffer (and easily edit them), and attach DOS commands to the F3 through F12 function keys. ALIAS, written by Douglas Boling and Jeff Prosise of PC Magazine. ALIAS lets you do easy command line editing, recall previous commands, and assign short "aliases" or function keys to DOS commands or environmental strings. =================================================== Author Information: Ken Johnson is Training and Support Manager at the law firm of Mayer, Brown & Platt in Chicago. He is a contributing editor to Hard-Copy, the Journal of the Chicago Computer Society, and a contributing writer to the Lawyers MicroComputer Users Group newsletter.