(Image: DOS Logo)

Doctor
DOS
Betamax's

DOS
COMMAND-LINE
SWITCHES


A Short Discussion of
Command and Program Modifiers

(Image: /-)
 


********

New users of DOS are often mystified by command
switches or they just don't bother to fully explore
their uses. This is a loss and their non-usage can
contribute to frustration at the command line because
ignoring them means more work and less productivity.


    The following is a short discussion of what switches are and why they might be used. Afterward, some pitfalls and tips 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.

    Be aware that not everything here may work for your version or manufacturer of DOS.


INFORMATION BELOW MAY NOT BE REPRODUCED
WITHOUT PERMISSION FROM THE AUTHOR ©


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 can narrow its focus to do more 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 decade and a half 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 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.)


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.)



SYNTAX

    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 note 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". That 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 & the 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.



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 & run by DOSKEY/4DOS and automatically incorporate your pre-selected switches.

    Secondly, one may use the DOS environment to set switches for some commands. 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 issued automatically whenever any of those commands are given.

    Perhaps later on, 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.
(*)4DOS links 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 have an extensive array available. 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, etc. - all 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. Note 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. Read the manual.


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 & 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/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 with 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 disc.

    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!.


 

Here are Some Switches Tips.



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