For years, PC users were f
orced to rely on
Microsoft's clumsy command processor for
scripting needs.
Very loosely based on the
UNIX shell, but
missing all the im
portant features (
regular expressions,
looping
constructs etc) , it was just about un
usable.
H
owever cr
eative users began finding nifty little tricks and
undocumented features which al
lowed batch files to do almost anything.
For many years,
PC Magazine had a
number of tips for batch pro
grammers.
Some c
ommon
tricks were:
- Piping the output of any command or the contents of a file into the 'date' command, which would then generate output like "Enter new date:x y z". Redirecting this output into a batch file and running it would result in a batch file called enter.bat to be executed finally delivering the input as command line arguments to be parsed.
- Storing goto label names in an environment variable to allow return to the same position simulating subroutine invocation.
- Getting user input by using the FC (file compare) command with the console and the null device, and using the above date trick to parse its output.
Since
Windows 2000, the command pro
cessor has been enhanced with:
- The ability to execute multiple commands on a single line ( using &, &&, or || ) similar to UNIX shells.
- Expression evaluation by the 'set' command.( Yes! you can do arithmetic ).
- New operator %~ which retrieves file size, date, time and a host of other functions for a given file.
- Enhanced 'for' command which can emulate a C for statement, recursively enumerate files, iterate over records in a file, iterate over command ouput a la the bash $() construct.
- 'if' commands can now do lexicographic comparision of strings.
- New predefined environment variables %RANDOM%, %TIME%, %DATE%.
- The :EOF extension for 'goto' which allows subroutine like behaviour.
- Extension to 'prompt' for showing UNC paths of network drives.
- Selective 'shift' command.
All these features put tog
ether make the batch language
powerful enough to write stand
alone appli
cations. There were powerful programs written even in the old batch language (TIC-TAC-TOE for
example) but not e
veryone could have written them. But it seems like too little, too late. Now theres VB
script and WSH and cygwin-b
ash and what have you. The one pl
ace where you really are stuck in the command line and need all the features is the Re
covery Console and Microsoft's prog
rammers have
sadistically provided a s
hell that is
even worse than DOS 2.0 ( NO
wildcards!, NO hi
story!, NO
command completion!).
Is it
Evil genius?
More like
Pure Evil (tm)!!
DOS is not dead!!