There is no standard for the batch language. Each interpreter defines it, and they agree on a core that goes back to the first versions of DOS. The dates below are the well-known ones; features given without a version are not tied to a release because that was not checked against a primary source.
What each interpreter knows
| Feature | COMMAND.COM (DOS) | cmd.exe | 4DOS / Take Command |
|---|---|---|---|
rem, echo, pause, goto, labels | yes | yes | yes |
%0–%9, shift | yes | yes | yes, with %# and more |
if (string, exist, errorlevel), for in do | yes | yes | yes |
set, %name% | yes | yes | yes |
call of another batch file | yes | yes | yes |
call :label, goto :eof, exit /b | no | yes (extensions) | GOSUB / RETURN |
& && || between commands | no | yes | yes, with ^ as the separator in 4DOS |
if /i, if defined, EQU … GEQ | no | yes (extensions) | own IFF and expressions |
for /d /r /l /f | no | yes (extensions) | own FOR and DO |
set /a, set /p, setlocal, endlocal | no | yes | yes |
%var:~n,m%, %~dp0, !var! | no | yes | functions such as %@LEN[...] |
| Long file names, spaces in names | only through lfnfor and quotes on Windows 9x | yes | yes |
| Unicode text | no | no (code page); cmd /u output only | yes in the Windows versions |
MS-DOS and COMMAND.COM
Batch files exist from DOS 1.0 (1981), when a .BAT file already took
%0 to %9. Later versions of DOS added the environment and
%name%, if, for, shift, errorlevel,
redirection and pipes, call, the @ prefix, choice as an external
program, and, in MS-DOS 6, start-up menus in CONFIG.SYS; which release added which was not
checked here. COMMAND.COM is a 16-bit program with a very short command line limit (127
characters is the figure usually given) and eight-character file names. The same interpreter ran
under Windows 95, 98 and Me, with long file names and start added, and under the
NTVDM of Windows NT for 16-bit programs.
AUTOEXEC.BAT and CONFIG.SYS are the start-up files. Only
AUTOEXEC.BAT is a batch file; CONFIG.SYS has its own syntax.
Windows NT and cmd.exe
Windows NT replaced COMMAND.COM with cmd.exe, a 32-bit program, and added
the .cmd extension. cmd.exe is still the Command shell of Windows 10 and 11
and Windows Server, run in the console host or Windows Terminal; Microsoft’s command reference notes
that “users seeking more advanced capabilities are encouraged to explore PowerShell”.
- Command extensions are the larger language:
if /i,defined, the comparison operators,cmdextversion,for /d /r /l /f,set /aand/p,%var:~n,m%, the%~modifiers,call :label,goto :eof,setlocaloptions,exit /b, the dynamic variables,pushdandpopd,mkdircreating whole paths andstart. They are on by default, and are switched withcmd /e:on|off, theEnableExtensionsregistry value orsetlocal enableextensions|disableextensions. SS64 givesCMDEXTVERSION1 for Windows NT and 2 from Windows 2000. - Delayed expansion (
!var!), off by default, is switched withcmd /v:on|off, a registry value orsetlocal enabledelayedexpansion. - File name completion with Ctrl+D and Ctrl+F is off unless set with
cmd /f:onor theCompletionCharregistry values; it is an interactive feature, not part of scripts. - AutoRun. Commands in the
AutoRunregistry value run when eachcmd.exestarts unless/dis given. A script that must not depend on them is run ascmd /d /c. - 16-bit programs run under
NTVDMon 32-bit Windows withAUTOEXEC.NTandCONFIG.NT; 64-bit Windows has noNTVDM. - .cmd against .bat: see Errorlevel and exit codes.
OS/2 CMD.EXE
OS/2 uses .CMD files for both its batch language, much like DOS’s, and REXX programs,
which must begin with a /* */ comment. The first line extproc hands a
.CMD file to another program. Windows NT adopted the .cmd extension from
OS/2. A file with this extension that starts with a comment is a REXX program; the viewer tells them
apart that way and shows REXX without colour.
4DOS, 4OS2, 4NT and Take Command
JP Software made replacement shells: 4DOS for DOS, 4OS2 for OS/2, 4NT for Windows NT and later Take
Command, which adds a console and an editor. Their batch files use .bat, or
.btm (“batch to memory”), which is loaded once and so runs faster and can change the
file on disk while it runs. They are supersets of the language above. Features from JP Software’s
documentation, summarised here and not checked on a running copy:
- Structured
IFF condition THEN … ELSEIFF … ELSE … ENDIFF,DOloops,SWITCH, andGOSUBwithRETURN. - Variable functions written
%@name[args](string, file and date functions) and internal variables such as%_cwd. - Aliases, command groups with
^or&separators, and extended wildcards and redirection.
Take Command is still sold and updated by JP Software. The viewer colours a .btm file with the
same scanner as a .bat, so the 4DOS-only commands stay plain.
Other implementations
- FreeDOS – its
COMMAND.COM(FreeCOM) follows MS-DOS and adds a few extensions of its own. - ReactOS – has a free
cmd.exewritten to match the Windows one. - Wine – ships a
cmd.exeof its own that runs batch files on Linux and macOS. - DOSBox – its built-in shell runs a subset:
.batfiles withgoto,if,for,call,shiftandecho. - PowerShell – the successor, with
.ps1scripts. It runs a.batby startingcmd.exe.
Not described
Known, not yet covered
- Reference: the complete 4DOS and Take Command command set and function list; JP Software publishes its help.
- Reference: the FreeCOM and DOSBox shells’ exact feature lists.
- Viewer: 4DOS and Take Command commands and
%@function[]forms are not coloured.
Unknown
- Reference: which DOS and Windows release added each feature, and the 127-character
COMMAND.COMlimit, were not checked against a primary source. Most rows of the table are from memory of the documented behaviour and were not run on each interpreter for this page.