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.
A 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?
Adding a plus sign before a command does some pretty weird things in DOS.
Try this for example, and watch the path in your prompt:
C:\>+MD C:\>+CD C:\D>CD.. C:\>+RD C:\>+CD Directory not found C:\>
It seems that, for example,
+COPY C: is interpreted as
COPY Y C:
+DIR will 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
ATTRIB *.* -S -H -R -A
Should work in MS-DOS 5 and 6.* and IBM DOS 5 through 7.
Both NT and OS/2 offer the ˆ (caret) as an escape character for command lines. Both will display:
Usage: ABC.BAT <drive:>
when you issue the command:
ECHO 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.
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:
SET TODAY=ˆ 02/23/2019 ECHO Today=%TODAY%
In NT, the resulting output would look like this:
That makes this trick really useful in NT.
The second line, containing the date, could come from the
DATE/T command in another batch file, for example.
In OS/2, however, the output from that same batch file looks like this:
However, the command
SET Today will display:
The only way to make OS/2 display the value of the DATE variable is:
SET Today| FIND /V "Today="
(No space between Today and | allowed)
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 moc.eduowrednavbor@ofni .
Besides 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:
SET /A variable = mathematical expression
If, however, all you need to do is display the result of the expression on screen, you can use SET like this:
SET /A mathematical expression
SET /A 75 / 5
will display 15 on screen.
An extra "bonus" feature is the way the result of the expression is displayed: without a carriage return/line feed!
(SET /A 75 / 5) > TEST.TXT
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.
Ken Gould also mailed me a trick to use when you do want a carriage return/line feed at the end:
(SET /A 75 / 5) | MORE > TEST.TXT
TEST.TXT's size will now be 4 bytes, due to the carriage return/line feed pair added by MORE.
If you prefer internal commands, use this instead:
(SET /A 75 / 5) > TEST.TXT ECHO.>> TEST.TXT
This SET /A feature can be used as a command line calculator.
Don't, however, expect it to work in the following batch file:
SET /A %1 %2 %3 %4 %5 %6 %7 %8 %9
SET /A %*
Calling this batch file with the arguments
12 + 3 will return nothing.
This behaviour seems rather inconsistent.
What does work is this:
SET /A Result = %* SET Result
Both Windows 2000 and XP show the same results.
This tip was shown to me by Chris Moore. Thanks.
Robert Van Etta reported some very odd behaviour of the
ECHO command in Windows 2000/XP/Server 2003.
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:
> MYINPUT.TXT ECHO ˆ
Too bad it won't work in a batch file...
to create an empty (zero bytes) file I always used:
TYPE NUL > new_empty_file_name
Robert Van Etta showed me an even shorter command:
Benny Pedersen has listed some pretty weird but definitely very useful behavior of the IF ERRORLEVEL command on his DOS/batch page.
page last uploaded: 2018-12-20, 10:50