|
Doctor DOS Betamax's |
DOS
|
New DOS users are often mystified by
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 |
NOTHING IN THIS ARTICLE MAY BE REPRODUCED
WITHOUT PERMISSION FROM THE AUTHOR ©
Topics
|
||
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.)
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.
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.
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.
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?
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.
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!.
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!.