Useless tips?This page shows some, er, let's call it "unexpected" behaviour of various DOS commands.
Many will be of no practical use -- hence this page's title -- but it may be fun to experiment with them.
DOSKEY and SET /PA tip by Padmanabha Holla:
If you have a doskey macro defined and if you input that macro string as input for any
SET /P varname=command, later on varname contains the alias of your input, not your input!
SET /P Test=Macro1?
SET /P Test=Macro2?
SET /P Test=Macro3?
+ PrefixAdding a plus sign before a command does some pretty weird things in DOS.
Try this for example, and watch the path in your prompt:
It seems that, for example,
C:\>+MD C:\>+CD C:\D>CD.. C:\>+RD C:\>+CD Directory not found C:\>
+COPY C:is interpreted as
COPY Y C:
+DIRwill be interpreted as
The effect of the + before a DOS command is that the last character of the DOS command is inserted as the first command line argument.
This works for COMMAND.COM's "internal commands" only.
As I said, pretty weird and pretty useless.
Unless, of course, you are looking for a way to make your batch files hard to understand.
(Thanks for Günther Brunthaler for helping me work out a proper description of the effect).
Note the comma.
Removes all attributes from all files in the current directory, like
Should work in MS-DOS 5 and 6.* and IBM DOS 5 through 7.
ATTRIB *.* -S -H -R -A
Escape CharactersBoth NT and OS/2 offer the ˆ (caret) as an escape character for command lines. Both will display:
when you issue the command:
Usage: ABC.BAT <drive:>
Both NT and OS/2 show some unexpected behavior when the escape character is used as the last character of the command line.
ECHO Usage: ABC.BAT ˆ<drive:ˆ>
The first time I heard about this strange behavior was in a post from Mark Stang in the alt.msdos.batch news group.
Let's take this simple batch file, for example:
In NT, the resulting output would look like this:
SET DATE=ˆ 12/12/99 ECHO Date=%DATE%
That makes this trick really useful in NT. The second line, containing the date, could come from the
DATE/Tcommand in another batch file, for example.
In OS/2, however, the output from that same batch file looks like this:
However, the command
SET DATEwill display:
The only way to make OS/2 display the value of the DATE variable is:
(No space between DATE and | allowed)
SET DATE| FIND /V "DATE="
In NT, the caret at the end of the line is interpreted as "skip the following linefeed".
In OS/2, the SET command interprets the caret as an escape character for the following linefeed, so the variable will contain a linefeed. A pity it cannot be displayed using %variable%, that would have allowed multiple lines of text in a single variable.
Right now, in OS/2, the only use I could think of is for hiding variables.
If you did find any other way to use this "hidden feature", please send it to my e-mail address.
SET QuirkBesides the "long list of known problems" with NT's SET /A switch, it has some "unknown" features too.
I haven't found a useful application of the following features yet, maybe you can think of some.
These features were mailed to me by Ken Gould. Thanks.
The common way to use the /A switch is like this:
If, however, all you need to do is display the result of the expression on screen, you can use SET like this:
SET /A variable = mathematical expression
SET /A mathematical expression
will display 15 on screen.
SET /A 75 / 5
An extra "bonus" feature is the way the result of the expression is displayed: without a carrige return/line feed!
The file TEST.TXT will contain one line with nothing but the number 15 and no carriage return/line feed. Check the file size, it will be only 2 bytes.
(SET /A 75 / 5) > TEST.TXT
Ken Gould also mailed me a trick to use when you do want a carriage return/line feed at the end:
TEST.TXT's size will now be 4 bytes, due to the carriage return/line feed pair added by MORE.
(SET /A 75 / 5) | MORE > TEST.TXT
If you prefer internal commands, use this instead:
This SET /A feature can be used as a command line calculator.
(SET /A 75 / 5) > TEST.TXT ECHO.>> TEST.TXT
Don't, however, expect it to work in the following batch file:
SET /A %1 %2 %3 %4 %5 %6 %7 %8 %9
Calling this batch file with the arguments
SET /A %*
12 + 3will return nothing.
This behaviour seems rather inconsitent.
What does work is this:
Both Windows 2000 and XP show the same results.
SET /A Result = %* SET Result
This tip was shown to me by Chris Moore. Thanks.
ECHORobert Van Etta reported some very odd behaviour of the ECHO command in Windows 2000/XP/Server 2003. Type:
at the command line (doesn't work in batch files) and you will be prompted for "More?".
Type in any text, followed by the Enter key, and it will be echoed again.
To store this text into a file, type:
Too bad it won't work in a batch file...
> MYINPUT.TXT ECHO ˆ
Create Empty Filesto create an empty (zero bytes) file I always used:
Robert Van Etta showed me an even shorter command:
TYPE NUL > new_empty_file_name