command.com is a magic file (specifically, a .COM file). It is, essentially, DOS.

Unlike *nix, DOS's commands are embedded in command.com. Want to hack dir so it replaces all instances of e with 3, so you can be a h4x0r? Tough luck. You have to modify command.com to do that, and command.com ain't open source.

On the other hand, command.com is rather efficient in that, along with a few helper files (most notably CONFIG.SYS, and AUTOEXEC.BAT), it provides a basic OS with scripting (sort of) in less than 300k of memory. Or, it used to. Nowadays, you'd better have extended memory set up right if you want to sneeze.

An excellent example of monolithic coding.

From wharfinger: not *all* dos commands are in command.com; just most. and it runs like-named batch files before built-ins, if the .bat is in %path%. Sorry, wharfinger, I removed your mandatory microsoft rant. ;)

It is somewhat incorrect to say DOS' commands are embedded in command.com. There are MS-DOS commands which are implemented in the command.com, but then again there are commands that are built-in to shells like bash. Ever seen an executable for cd, logout, history, or bg? Heck bash even does kill. One way to think about it is, command.com is the shell and io.sys is the MS-DOS kernel.

After your computer boots, it kicks up the hard drives, reads the boot sector, the boot sector loads and executes io.sys, and io.sys loads config.sys to see if you have changed your COMSPEC. If the COMSPEC is nil, it is defaulted to c:\command.com. Io.sys then kicks up your shell (usually command.com).

Interestingly enough, command.com hasn't actually been a com file since back in the early days of DOS. You can tell (the same way the DOS kernel does actually) by looking at the MZ signature at the beginning of command.com. Command.com is actually an exe file.

One of the cute things you can do with command.com is to hexedit the strings for the command names to something else. Then create a .BAT file with the same name as the command.
Example:
Command.com: dir --> fff

dir.bat:
@echo off
rem ph33r my m@d sk177z!!!!!!!!
fff %1 %2 %3 %4 %5 %6 %7 %8 %9 /a-h


Now DIR won't list hidden files (including your hidden dir.bat). The script kiddie potential is marvelous (similarly, editing io.sys to change autoexec.bat and config.sys to differently named, hidden files)...

This was, of course, much more useful back in the days of dos 3.30, before programs like file manager made it easy to see what was going on.
To replace all instances of e with 3, so you can be a h4x0r, you could probably use ANSI.SYS to remap the screen, but that would do every text-mode program. (Which is probably all the more 1337).
And command.com won't run a dir.bat before dir builtin, even if it is in the %path%. It will, however, run an attrib.bat before attrib.exe, if attrib.bat is further ahead in the path.

Finally, there is a shell for linux called sash (stand alone shell) that has builtins for ls, mv, etc. just like command.com

Log in or registerto write something here or to contact authors.