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.
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 DIR R
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).
ATTRIB,
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 DATE=ˆ
12/12/99
ECHO Date=%DATE%
In NT, the resulting output would look like this:
Date=12/12/99
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:
Date=
However, the command SET DATE will display:
Date=
12/12/99
The only way to make OS/2 display the value of the DATE variable is:
SET DATE| FIND /V "DATE="
(No space between DATE 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.
Please, let me know if you did find any other way to use this
"hidden feature":
BX 8H8 UZPUKTM WT TK 8T
EM F5HR BN5WW53BUPFY Y3 MN 85
UK 5HZF KDXB WT YF DY
WK FDD HU3 WN 58 KN
PY TM H35Y XVTBVT D33T HY PMV Z5 8P TX YW8 YYEE PD VBUB 5P MB TWZF8D VY UMDE 3WPT 3U 5D8D RB X3Y PX T NV UYDB FT 5D DMWX EB WNBM RXH3 PMDD TU VD3X TTUD
TR EWV8PRF3 NN8PNT WTHFDEPB VZ URWPRB BY 3RU HZXX83 E5E5VEUT EWW8NPUR W5 8Y PVTMXFPKY KVZBDMMH MZ8DUETX HHB5F8ZH ZHWFUH Y3 3XK 8M YTHTDP3E X5 H8 KHPBYMWZ NHX3YWMN EFMNY5K XNRYREDW MKTRRTD M3MHUX
RV 5NY WHV EV VT DF VV 88H UMM ZU MDX 38 ZK ZYK BZ XK XU UE MZ KXB VYR 5W XD3 X8 MR RY5 K FUM 5 HK DM W3 EF UR ZX5 KT BU BU TRZ VT ZM H8B XPM 8H
3P XY NZ 3P NM B3 TU XP R3 3N RH NR D5 H8 3F 3K F8 VK EY UW 8N ZH BR FH 3R XK 3 8 ET HY XH DR RV WB 8T W8 FU X3 UM YV R5 KN HF TV
NT V3 YR 53 F8 VZ MF FF 3F EW NF 8Z KK FZ D8 ZF 5V FW8TK YU HN YM EU NU8T5MRUR5 8D MB Y5 5K UY MK NN DW FV RU 3H VMH5TBUF5M XZ VB YE DD YK FW
ED RM VB YY TD PV WP 5B UU HX 85 XD 3R B3 ZT RE RK EZZEETEF UR BB 8W WD RFHNTXU55D DK XN UN Z8 MF FK DK VX UF 5N V5 FMEUNKUXBK ZF 5M NV MZ FE T8
HX WD 55 W3 WK HT H5 WY U H3P BT 5R HR X3 YE T8 HK BYMR VH 8B 8X PE R5 NX 3N ND YH YM 5Y 5E RM NP XU UX NV EB TF WV HX K5 NY ZP
8P 5H 5W ZU PY VX U5 3E EH EV EW R8 UV FE MF FM FH VX 5F FZ VB 8Z R5 ZN 3T P D E B 8V N8 BP UM EN 5H HY RX ZK FY TK TP ZB UY
83 TU FM HV WB BD D5 HDB MHV FF ZW 8T Y5 DYY NV XUY BU UPV BR FV N3 UZD RB 3XM MF YZE VTE 8B WK T5V WKF X8 T3T 5V XHE B8 MED BH HU UE FW Z8
WN E3 ZY BU YUZZWPRZ UV 55EPDZB8WKN 3U Z5FMPP3Z YBVMFRBH KKZ ZRKBFF8VT RU 5X E3BNUPVU PYFWTPNP ZR UTN 3KN ZHMW5YR5 TT5UN8XT UENHPPDH M8HDRHZF MB 55VMZ8R HXW5HU5B Y8 8F YM
F5 UW ER KE VMHE 583 YVUK 8RNY HP XV HUKH 8K YHBW Z V3UXF ZM RV XX ZH3B PR PNTFF M5 NB DV TTZ5 WDV3 R5 X8Z3 WE 8XTUR HW MRE5K P3RT NT WV UN
UWD XM
YT8K PPR
ZKYPEVWRMWKF
UTYDTXZV
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
For example:
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 carrige return/line feed!
Try this:
(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
nor in:
SET /A %*
Calling this batch file with the arguments 12 + 3
will return nothing.
This behaviour seems rather inconsitent.
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. Type:
ECHO ˆ
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:
CD.> new_empty_file_name
Benny Pedersen has listed some pretty weird but definitely very useful behavior of the IF ERRORLEVEL command on his DOS/batch page.