Before you can begin to write batch files, you need a tool to do your writing with. OS/2 comes with the perfect tool, its Enhanced Editor in the Productivity Folder. This chapter presents a brief tutorial on starting and using the OS/2 Enhanced Editor. It concentrates on those features most useful for writing batch files. For more information on all its features, see your OS/2 documentation.
Before I cover the OS/2 Enhanced Editor, let me say a few words about alternatives. Almost any word processor or editor-no matter how simple or advanced it is-can be used to write batch files. Many batch files have been written under DOS with Edlin, one of the weakest and most difficult editors ever written. By the same token, I've written a number of batch files using Microsoft Word, one of the most powerful word processors available.
Batch files must be saved as unformatted text. Any editor or word processor that can save unformatted text (also called ASCII or plain) can write batch files. If you are not sure about your editor, try creating a small batch file with it and saving it as unformatted. Then try to run that batch file. If it runs ok, then your editor is fine for writing batch files.
The Enhanced Editor is fairly powerful for an editor. It offers features like search and replace, moving text, word wrap and editing multiple files. In fact, if your needs are simple, you could use the Enhanced Editor for all your word processing. This chapter presents a tutorial to the Enhanced Editor. If you are experienced with editors in general you might want to skip the first few sections in this chapter. If you plan on writing your batch files with your word processor or another editor, you might want to skip this chapter altogether.
To help you understand the file format used by the Enhanced Editor, let's try an experiment first. Create a small file (say one or two paragraphs) with the word processor you normally use. Be sure to format all the text like you normally would. When you have finished, save the file and exit your word processor. Now, drop out to the OS/2 command prompt and change to the subdirectory containing your file. Once you have done that, issue the command "TYPE MYFILE.TXT" only change MYFILE.TXT to the name you used to save your file.
This command causes OS/2 to display the contents of your short file to the screen. You should see most of the text you entered in the file. However, you should also see a lot of characters you did not type. These characters contain the formatting information your word processor adds to the file. Some word processors, like Microsoft Word, add file summary information to files and you will see these characters as well.
While this information is useful to your word processor and help makes your file look attractive when it is printed, it is poison to a batch file. Batch files must be saved containing the text you enter and nothing else. This format is called an ASCII file. ASCII files are sometimes called unformatted files. The Enhanced Editor creates ASCII files automatically. To see this, create a small file with the Enhanced Editor, save it and then exit to the OS/2 command prompt and type that file to the screen with the command "TYPE MYFILE.TXT" only again using your file name. This time, you will not see any extra characters.
Formatted files are poison to a batch file.
Because of the Enhanced Editor's limited formatting abilities, it's not the best choice for serious word processing. However, the Enhanced Editor is one program where it's safe to format your batch files for printing since it stores all formatting information in the Extended Attributes file. In addition to writing batch files, it's great for editing system files like your CONFIG.SYS file, keeping simple todo lists if the OS/2 Todo program is not to your liking and for writing brief memos or notes to yourself. It's also a good way to view the documentation files that come with more shareware packages even if you have no intentions of making any modifications to these files.
The Enhanced Editor is stored in the Productivity folder, which is stored inside the OS/2 System folder. The steps and figures below assume that you have left the Enhanced Editor in that location. If you've moved, you'll have to alter these steps. Figure 1-1 below shows a typical OS/2 desktop. Move the mouse cursor to where it is inside the OS/2 System icon (on the left near the top) and press the left mouse button twice very quickly. (pressing the left mouse button twice very quickly is called "double clicking.") This opens the OS/2 System folder. Your system should look something like the one shown in Figure 1-2.
Next, move the mouse cursor over the Productivity folder and again double click the left mouse button. This opens the Productivity folder. You system should look something like the one shown in Figure 1-3. Move the mouse cursor over the Enhanced Editor icon and once again double click. This opens the editor with a blank file ready to accept characters. Figure 1-4 shows this.
I use the Enhanced Editor a lot so I created a "shadow" icon on the desktop itself to speed starting the Enhanced Editor. To do this, click on the Enhanced Editor icon using the right mouse button and select "Create shadow" from the menu. When it asks you for a location, select the desktop.
Make the Enhanced Editor a shadow on the desktop to quickly create and edit batch files.
Notice in Figure 1-4 that there is a line saying "=====Top of File=====" at the top and one saying "=====Bottom of File=====" at the bottom. These are there as markers. You can not delete them and they are not saved as part of the file you are creating. Also notice from Figure 1-4 that the Enhanced Editor has a status line at the bottom of the screen, a menu along the top of the screen and a title bar above the menu screen.
We will explore the menu bar later but let's take a minute to review the status line at the bottom of the screen and the title at the top. Figure 1-5 shows the Enhanced Editor being used to edit an early draft of this chapter. At the time I took this screen show, I was editing line 67 of 67 so the file had 67 lines in it and I had the cursor on the last line of the file. The cursor was near the right side of the screen in column 110. I only had this one file loaded into memory so the status bar showed "1 File". I had the Enhanced Editor in insert mode so if I move the cursor to the middle of the file and start typing, the new characters are inserted rather than overwriting existing characters. Finally, the file had been modified since the last time I saved it so the status line displayed a "Modified." From the top of the screen, you can see that the name of the file I was editing was "D:\BOOK11\EDITOR.DOC".
If you have not yet done so, start the editor so you can follow along with this example. Notice that there is a flashing vertical black line on the screen. This is the cursor. It is always located on the space where the next character will be inserted into the file. The line and column numbers on the status line are referring to the position of this cursor.
One of your most common editing activities will be to move this cursor around to different locations to insert or delete text. The Up, Down, Left and Right cursor keys move the cursor one space in the associated direction. The Control-Left and Control-Right cursor key combinations moves the cursor one word in the associated direction. PgUp and PgDn move the file one page in the associated direction. Ctrl-PgUp moves the cursor to the top of the current page while Ctrl- PgDn moves it to the bottom of the current page. Home moves the cursor to the to the beginning of the current line while End moves it to the end of the current line. Ctrl-Home moves the cursor to the beginning of the file and Ctrl-End moves it to the end of the file. Table 1-1 below summarizes this.
Moving the cursor around with these keys can be cumbersome when you need to move the cursor up twelve lines and over eight words. Fortunately, the Enhanced Editor has a speedier way. In addition to the text cursor, you should see a mouse cursor. It looks like a large capital "I" with the top bars bent up and the bottom bars bent down. If you move it outside the editing area, it changes to an arrow. To move the text cursor quickly to any point on the screen, move the mouse cursor there and click once.
The mouse cursor can also be used to easily scroll around the file. The small gray bar along the right side of the screen is called a "mouse elevator." A smaller gray bar indicates the current position in the file. Clicking above this bar works just like pressing PgUp while clicking below it is just like pressing PgDn. Notice that there is also a mouse elevator above the status bar for moving the file to the left or right when it is too wide to fit on a single screen.
Go ahead and create the following four-line batch file by entering the text using the Enhanced Editor exactly as it is shown below :
ECHO This Is A Simple Batch File Example ECHO The Name Of This File Is SAMPLE.CMD ECHO You'll Use SAMPLE.CMD To Illustrate ECHO Using Enhanced Editor
Save the file by pressing the F2 key and using the name SAMPLE.CMD. This is a simple OS/2 batch file. The ECHO command causes the text that follows to be displayed on the screen. We will cover the batch file commands in a later chapter so don't worry about that now, this is just sample text to learn the editor with.
To see how to insert text, move the text cursor to the left of the "Batch" on the first line. Check the status bar to make sure the Enhanced Editor is in insert mode (if you see a "Replace" then press the Ins key to toggle to insert mode.) Now, type in "OS/2 ". See how the text to the right of the cursor moves over to make room for the new text. Now move the cursor to the "You" on the third line and press the Ins key to toggle to overstrike mode. Notice that the "Insert" at the bottom of the screen changes to a "Replace" and the text cursor changes to a black box that covers one character. That covered character is the one that is about to be replace. Type "We" to replace "You" and press the Del key to delete the remaining "u" character.
As I introduced above, the Del key is one way to delete characters. In replace mode (also called overstrike mode) pressing the Del key deletes the character inside the cursor. In insert mode, it deletes the character to the right of the text cursor. In either replace or insert modes, pressing the Backspace key deletes the character to the left of the text cursor key.
There are two other ways to delete text and you generally use these on larger blocks of text. With both of these approaches, you begin by highlight the text to delete. To highlight with the mouse cursor, you move the mouse cursor to the first character to delete, press and hold the right mouse button and drag the cursor to the last character to delete. As you do this, everything you are highlighting is shown inside a black box. To highlight text with the cursor key, move the text cursor to the first character and hold down the shift key while using any of the cursor movement keys to move the text cursor to the last character to delete. Using either method, once the text is highlighted you can press the Del key to delete it or simply begin typing. The first letter you type placed in the file and all the highlighted text is automatically erased.
I should mention that some keyboards have trouble selecting text using the keyboard method. My Gateway 2000 computer will only do this using the cursor arrow keys next to the letters. The cursor pad on the far right just enters numbers when you press the shift key. If you have trouble with your keyboard, you might want to experiment with using different cursor keys, turning on the NumLock and trying both Shift keys.
We now need to cover some of the Enhanced Editor menu items. Like most OS/2 programs, you have two ways to access the menus. The first is to move the mouse cursor to the desired menu and click once. You can also use the keyboard. First, press the Alt key. That causes the File menu to be highlighted. Use the arrow key to highlight the desired menu and then press Enter to bring up that menu. If you are using a mouse, you can point to the option you want from a menu and click on it to execute it. If you are using the keyboard you move the highlight to the desired option and press return. Figure 1-6 shows an early draft of this chapter with the File menu pulled down.
To save a file, you pull down the File menu and select the Save option. Notice that this option has an "F2" shown out beside it. That indicates that pressing the F2 function key is a "keyboard shortcut" that lets you save a file quickly without the need to work through all the menus. Any menu option that has a keyboard shortcut will have it printed on the menu as the Save command does. If you use the Enhanced Editor a lot, you will want to learn to use a few of the more common keyboard shortcut keys as pressing F2 is the fastest way available to save a file.
Keyboard shortcuts make quick work of the more common menu options.
To open a file that already exists on the disk to either edit, print or read, bring up the File menu and use the Open command. If you want to start a new file without having to exit the Enhanced Editor first, bring up the File menu and use the New command.
The File menu offers the following additional commands:
The Edit menu is used primarily for working with blocks of text. Recall from the discussion above that text can be selected using either the keyboard cursor keys or the mouse cursor. Once that block is selected, in addition to deleting it, you can use the Edit menu to operate on it. Selecting Copy from the Edit menu places a copy of the text in the paste buffer without disturbing the original text. The paste buffer is a special holding area for text. Only one block of text can exist in the paste buffer at a time so if there is already text in the paste buffer then selecting the Copy command replaces the text currently in the paste buffer with the highlighted text. If you select Cut rather than Copy, then the text is still placed in the paste buffer but it is also removed from the file.
Once there is text in the paste buffer, you can move the text cursor to any location you like and copy the text in the paste buffer to the file using the Paste command. Doing this does not disturb the text in paste buffer so you can make as many pastes of the same text as you like. Cutting and then pasting is how you move text around in the file. Copying and pasting is how you make copies of text in the file. The text remains in the paste buffer as you move between files (but not when you quit the Enhanced Editor) so this is an easy way to copy or transfer text between different files.
Another function of the Edit menu is to let you "undo" or reverse changes you have made. It offers two options for doing this, Undo line and Undo. The Undo line command lets you reverse any changes you have made to the current line. Once you move the cursor off the current line, the Undo line command no longer works. If you select the Undo line command by accident, you can select it again to reverse the undo operation.
The Undo command lets you undo commands even after you have moved off that line. When you select the Undo command, it brings up a dialog box with a mouse elevator. As you click on the mouse elevator, successive actions are reversed. You should be able to see the changes taking place on the screen underneath the dialog box. This box allows you to reverse multiple changes.
The Enhanced Editor offers search as well as search and replace. Go back to the original SAMPLE.CMD batch file and move the cursor to the top of the file with the Ctrl-Home command. Select the Search menu and then the Search command from that menu. This brings up a dialog box where you enter the text to search for and optionally, the text you want to replace it with. For practice, try searching for the text "name" without replacing it with anything. Once the Enhanced Editor locates the text, it draws a circle around it. Had you misspelled a command, you could have the Enhanced Editor go ahead and replace the misspelling with the proper spelling by entering it in the replace field.
There are five options buttons for a search or search and replace:
Once you have entered your search text and optionally your replace text, there are six different buttons at the bottom you can use to start the process:
While you have SAMPLE.CMD loaded, add the line "@ECHO OFF" to the top of the file and the line "PAUSE" as the last line in the file. These should be entered without the quotation marks. We will be using SAMPLE.CMD in the next chapter and these two changes will make it work better as an example. Their meaning will be explained later. The final batch file should look like this:
@ECHO OFF ECHO This Is A Simple OS/2 Batch File Example ECHO The Name Of This File Is SAMPLE.CMD ECHO We'll Use SAMPLE.CMD To Illustrate ECHO Using Enhanced Editor PAUSE
Often times, it's useful when writing a new batch file to have an existing batch file handy to look at to copy some of the syntax. The Enhanced Editor allows you to scroll between several different files. You can copy the commands you are interested in from the existing file and paste them into the new file. The Enhanced Editor also gives you several different ways that you can look at both files at once.
The first way is to put both files on the screen at once. To do that, first load the existing file into the Enhanced Editor. Move the mouse cursor to the very right of the screen. It will turn into a two-sided arrow. Press the left mouse button and drag the border to the middle of the screen. If you need to reposition the smaller screen, you can move the mouse cursor to the title bar and while holding down the left button, move the window to where you want it. Next, use the Open command to open the next file (or the New untitled command to start a new on) and use the same technique to size it and place it beside the original screen. Using this approach, you can look at both files at once. Use the mouse cursor to click on one or the other to make that screen the active screen for editing the file.
If you want to switch between different files for editing but don't need to see more than one at a time, then ring editing is a better approach since it lets you use the entire screen for one file. First, pull down the Options menu and move to the right of the Preferences menu. Move the cursor down to the Ring enabled menu and press return. Two buttons that look like rings will appear near the top right of the screen. Next, pull down the File menu. It will now have a new option, Add file. This lets you insert another file to edit into the ring of files. You use the Quit command from the File menu to remove the current file from the ring.
You have two different ways to switch between the various files in the ring. The first is to click on either of the two rings at the top of the screen. They move you in different directions through the ring. The second method is to use the List ring command from the Options menu. This lists the titles of all the files. To switch to one, highlight it and click on the Switch button.
If you find learning the Enhanced Editor too much just to create a few batch files and you are looking for something simpler, OS/2 has just the thing for you. It's called the System Editor. It's much like a stripped down Enhanced Editor. Under the File menu, you'll find New, Open, Save, Save as and Autosave and nothing more. Under the Edit menu, you'll find an Undo button, the block commands of Cut, Copy and Paste, a Clear command to erase the highlighted block, and Find and Select all commands. The Option menu lets you set the color and font and turn word wrapping on and off. That's it, nice and simple.
This chapter has explained how to use many-but not all-of the features of the Enhanced Editor. Rather than trying to cover all it's features, I've concentrated on those you are most likely to use while creating and editing batch files. To learn about its remaining features, check on the on-line documentation for OS/2 or pick up a general purpose OS/2 book.
© 2002 by Ronny Richardson, All Rights Reserved