(Image: DOS Logo)



A Brief Discussion of
Command and Program Modifiers

(Image: /-)



New DOS users are often mystified by
command switches, or they just do not bother
to fully explore switch usages. This is a loss, and
disregarding them can contribute to frustration at the
command line, making for more work and less productivity.

    Discussed here are the nature of switches and why they might be used. Afterward, some tips and pitfalls will be given. Deep detail will not be gone into. If you want to know more about using certain switches and how they modify a command, see your DOS manual's Command Reference or On-Screen Help.

Understand that not everything reviewed may
function for your manufacturer or version
of DOS, or for the software used under it.



Preliminary Switch Usage Switch Tips



What is a Command Switch?
    When one issues a DOS command, it does the work requested as per the design of that command. Thus, DIR places a list of file(s) in the current directory on to the screen, DEL removes the file(s) typed after the command, COPY makes a duplicate of the given file(s), and so on. Each command works in a defined way. However, it is possible to modify most commands so as to tailor them to do more specific things, or to display the result in a different way. This is accomplished through "switches".

    A switch is simply a command modifier, making it somewhat akin to "Properties" in Windows. It is a single letter, word, or word abbreviation that follows a command or its parameters. A switch is used to make each command more versatile by changing its workings, display method, or how it acts upon some parameter.

Why Might I Need, or Want to Use, a Command Switch?
    A command issued with no switches will work as defined by its default operation. However, the user may wish to have it work differently, or perhaps requires a different outcome and/or display than the command alone provides. Switches make a command more powerful, and they can narrow its focus to do very specific tasks.

    With the latest updated DOS commands, switches are even more numerous and important. Programmers have included more and more with each new command. The old XCOPY of a three decades ago had only 10 switches; XXCOPY alone has over 160! That makes XXCOPY far more powerful than XCOPY. Mastering even some of these will quickly escalate one to the level of power-user status, and this will allow far more work to get done with less input.

    Another usage is to configure, or even make direct use of, a software program right from the command line. (See farther on.)


Switch Usage

How Do I Use Command Switches?
    You use them by first determining what switches are available and their possible applications. This is found in the DOS manual's Command Reference, but is also available on screen in DOS versions after MS-DOS 5. (See the Tips section, farther on.)


    The syntax, ("sentence" structure) for using switches with DOS and most of the programs written for it is the command, followed by a space, a forward slash, and then a letter, word, or character string. If parameters such as file names and/or directory names are required, most times the switches go at the end of the command-line string. However, some commands of some DOS versions require the switches to be placed right after the command. Microsoft's MOVE command works that way.

    In addition, some switches allow the use of a `-' (minus) sign to reverse the action of a switch. (See the Tips section farther on.) Check the manual or on-screen help to see where switches are to be placed and if their actions may be reversed by using a minus sign.

Case Sensitivity

    Being used in or with DOS, case sensitivity is not usually a problem regarding switches. However, it's possible that it might be an issue with some versions, in some cases. So consult the manual of your DOS version to see if case makes a difference. Realise, DOS itself can differentiate case when a user types at the keyboard, but most switches allow for this. So generally, the switch itself may be typed in upper or lower case (or mixed case for switches of more than one letter.) However, it is possible that there may be some exceptions. See the manual to check for sure.

    Most exceptions for letter case lie with DOS programs. They differentiate between upper and lower case switch letters. PKZIP is one such program. While studying a program's manual or on-line help, keep an eye out for this possibility. As a related aside, some command-line history/recall programs, such as Toddy or DR-DOS's HISTORY, can be case sensitive when it comes to command recall or file/directory auto-completion. They may not display any previous commands (that could include switches) if the case does not match that which is typed at the keyboard. (Note that "DR-DOS" is pronounced "Dee-Arr DOS".)

    Remember to find out then, if the case needed to perform the work you require makes a difference when using switches with DOS programs.

Multiple Switch Use

    In some instances, more than one switch might be employed to narrow the focus of a given command further yet. As an example, if there are many files in a directory and one issues a DIR command to see a list of those files, they will scroll off the screen and the first ones will not be able to be seen. If there is a need to see those files, then instead of just typing "DIR", issue "DIR /P". This will Pause the screen when it fills so that you may read the first group. Then, striking a key allows the next screen-full of file names to be seen. This continues until all file and directory names have been listed.

    A multiple-switch example for this same command is if one wishes to see an alphabetised list by name and still pause the screen. Then the command is modified as "DIR /ON /P". This will give an Ordered list by file Name, Pausing after each screen fills. Note that the syntax requires a space between the switch and its command, but one between each switch is usually optional. For clarity and easy readability, I recommend placing spaces between switches, especially when composing batch files. I also recommend that switches be placed into alphabetical order for ease of reviewing when commands are within a batch file.

Other Switch Methods

    In addition, switches may be employed through two other methods. One is by using DOSKEY macros, or in 4DOS(*) they are called "aliases". This is beyond the current scope of this article, but basically, one may use a Macro or Alias to define the default methods of a given command. Thus, one may invoke the command without typing any switches because it will be intercepted and run by DOSKEY/4DOS, automatically incorporating your pre-selected switches.

    Secondly, one may use the DOS environment to set switches for some commands in some versions of DOS. Again, this is beyond the scope of this article, but it works similarly to DOSKEY. However, it is not available for every command. This method employs the environment command called "SET". One may specify switches for the DIR, COPY, XCOPY and MOVE commands. They will be automatically included whenever any of those commands are given.

    Perhaps in some later article, I will expand on both these methods. In the meantime, learn the basics of switches so you'll be ready should you choose to make use of either of these alternate ways in the future.
(*)Links to 4DOS may be found in DOS Websites.

What about Command-Line Switches Used by Programs?
    Most DOS programs have at least a few switches, while many provide an extensive array. They may be used to load one or more files upon startup, or to run the program in a particular configuration, usually including the ability to override one or more of the default configuration parameters.

    In addition, some programs and/or their utilities may be run directly from the DOS prompt without ever having to see or interface with the program on the screen. It can be a very powerful way to get work done faster and with fewer hassles. This is especially true if one places various switches into a series of batch files that can be run at will from anywhere within DOS. They can do file conversions, set up graphic slide shows, do disc maintenance or testing, and much more -- exclusively right at the command line.

    All the above can be implemented and varied through the use of switches, so it's well worth it to seek out their capabilities. As with DOS commands, one issues the program's or utility's executable followed by one or more of its switches. Realise though, that some programs use a different switch syntax. Some use a `-' (dash) to signify a switch, and some prefer they be located right after the program executable, as opposed to being placed at the end of the command string. Consult the manual or online help.

Are there any Difficulties I Might Encounter?

Switch Inconsistencies

    Aside from the issuing of a switch other than the one intended, a common problem results from inconsistencies among DOS commands using the same letter for a switch. For example, in different commands, the `/S' switch can mean "Case Sensitive", "Scan", "Share", "Sort", "Status", Subdirectory, "System", and others. `/P' can be "Path", "Pause", "Permanent", "Print", "Prompt", and so on. Many other commands use similar switch designators, but which mean different things from one another. Not only that, some switch meanings changed from version to version of a command. This confusion can lead to errors when issuing a command from memory.

    The 4DOS(*) COMMAND.com replacement has addressed this concern and is much more consistent from command to command. One way around this for those using DOS versions that are inconsistent, is to spend time learning those differences for the commands you use that would be affected. A better method is to place commands and associated switches into batch files. Since these files would be named by you, you could do so in such a way as to keep their purposes straight in your mind. This method also eliminates the possibility of mis-typing or mis-using a switch. Once you have tested and tweaked the batch file, it will always run with the switches as you intended. See Batch File Basics elsewhere at this website for help writing batch files. (Note too, that one might also use DOSKEY or 4DOS aliases, or environment variables, as mentioned farther back, to achieve the same purpose. However, they are generally not as versatile as batch files, and thus, are not as capable when it comes to complicated operations.)
(*)4DOS links may be found in DOS Websites.

Switch Interference

    Getting back to possible problems, another may occur if you use switches that are mutually exclusive or that interfere with one another. You might be lucky and just get an error message, but what may also happen is that one or more of the conflicting switches will be ignored. Thus, the command will likely not work as you intend -- worse, if an unintended, detrimental result occurs and gives no warning message.

    Another problem that comes to mind is in using switches with which one is not entirely familiar. Some switches with some commands can also be dangerous if their use is not fully understood. Examples are the automatic overwrite switch (/Y) in some DOS versions of the COPY, MOVE, XCOPY, etc. commands. Another is the same switch in DELTREE. That switch causes the deletion of files and subdirectories without prompting. DEFRAG /H will move hidden files. This is a dilemma because DOS and some programs expect to find certain hidden files in certain locations on the hard drive.

    There are other possible problems, but you need not worry as long as you study what each switch does. Then try them on duplicate files in a test directory where anything that goes wrong will not spell disaster. Once you become confident, the test directory will be less, or completely, unnecessary. Then you'll then be a switch guru!.


Switch Tips

  1.   Use `/?' at the Command Line.   Typing a DOS command followed by `/?' (or in some DOS versions, `/h'), will give a quick syntax, list of switches (if any are available), and in many cases, examples for the given command. Use this as a quick refresher for commands with which you are less familiar. (These are not available in all DOS versions.)

        As well, `/?' usually works with a program's or utility's main executable. However, be aware that some use a different switch prefix other than a forward slash. The most common of these is the `-' (dash).

  2.   Use DOS Help.   Regarding DOS commands, if you are unsure of one, but want more than the `/?' can provide, hit `F1', or type & enter "Help", or "Help (command)". More detailed information will be given on screen. Again, these features are not available in all DOS versions.

  3.   Place Switches in Alphabetical Order.   When entering a command's switches into a batch file, put them in alphabetical order. It won't mean much if you have just a few switches, but if there are many, using the same order each time makes it easier to scan a batch file at a later time to see which switches you have used. Knowing that one switch can only be seen after another means quicker scanning and faster comprehension of a given command. This is an aid to troubleshooting or when upgrading a batch file.

  4.   Use a Minus Sign to Reverse Some Switches.   Placing a minus sign between the slash and switch letter or character string reverses some switch actions. As an example, with some versions of the COPY command, using "/Y" suppresses the prompt that asks if you wish to overwrite a file. Using "/-Y" will always prompt you if a file is about to be overwritten.

        Note that some switch reversals are performed by placing the minus sign after the switch character. As an example, PKZIP has a switch for "Recurse Subdirectories". It's ` -r '. (Note that PKZIP uses the `dash' as its switch character.) The action of this switch is reversed by placing a minus sign after it: ` -r- 'so that subdirectories will not be taken into account.

        In other cases, the minus sign will reverse a sort order, or not include a selected parameter. It can also be used to disable certain things that would ordinarily be the default.

        Since this varies so much among DOS versions, commands, utilities, and program executables, study the manual or on-screen help to see whether a minus sign does anything at all, and if it does, exactly how it changes a switch.

  5.   Be Aware of Case Sensitivity.   As discussed in this article, some commands and programs have case-sensitive switches that perform differently depending on the case used. Be sure to check if this is so when using switches or writing them into batch files. Using PKZIP again, it employs `-t' to select files based on a date equal to, or newer than, the date typed, while `T' selects files that are older than that date. There are other case sensitivities regarding PKZIP's (and PKUNZIP's) switches, as well.

  6.   Use a Program's Switches.   Look in your software manual and at the on-screen "Read-Me" or document files for a list of switches available to use with programs. You may find innovative ways to use the program's capabilities right from the command line. Using such options in a batch file often means a program can run unattended. Thus, one may use such a setup to do a program's work right out in DOS.

        A good example is using a graphic program's conversion capability to change say, a .jpg image to a .bmp. Set this up in a batch file with the program's executable and its conversion switches set to your preferences. You will never have to actually start the program interface. One command in DOS, and the conversion is done from within any directory.

  7.   Have Batch Files Issue Switch-Modified Commands.   As already mentioned, placing commands and their switches into batch files is a good method. It serves a number of purposes:

Using switches is yet another key on the road to becoming a
DOS Power User. Learning what switches are available and
how they might be used, will improve productivity, lessen
frustration, and make you a true command-line wizard!.

Main DOS Page