Expanding the FreeDOS COMMAND.COM
The FreeDOS COMMAND.COM (also known as "FreeCOM") is a compatible equivalent to MS-DOS COMMAND.COM. FreeCOM doesn't do anything special; it just creates a command prompt that lets you run programs.
FreeCOM also supports the standard MS-DOS batch programming syntax. Any batch script that runs in MS-DOS should run in FreeCOM. And any batch script you write for FreeCOM will run in MS-DOS COMMAND.COM.
From a recent discussion on the email list, I'd like to suggest an extension to FreeCOM. Maybe this would be better implemented as part of a new alternative shell, but it would be really interesting to see it added as a feature to FreeCOM.
Here's my idea: create a BASIC-like programming language that also supports MS-DOS batch scripts.
DOS batch scripts are simple affairs. Really, the idea behind the MS-DOS batch was to "batch up" a bunch of simple commands. DOS batch programming supports minimal flow control. You can query the exit status (
ERRORLEVEL) of the previous command, and you can jump around the script (
GOTO) but DOS batch programming doesn't support much else.
I'd love to see an extension to DOS batch programming. Something like a BASIC interpreter would be interesting, if it executed commands in the PATH if the instruction wasn't a keyword.
I wonder if someone is interested in writing a BASIC-like "shell"? Something that uses a combination of BASIC and COMMAND.COM syntax would make the interpreter a "superset" of COMMAND.COM, and an interesting new alternative shell.
Some suggestions for how to extend BASIC and DOS batch programming include:
As in current DOS batch, variables can store either numerical or string data. Variable names can be of any reasonable length, and can be referenced in uppercase or lowercase.
SETto assign values to variables, and BASIC's
LETto assign values based on arithmetic.
LETbecomes a superset of
SETthat also supports arithmetic evaluation.
And surround a variable with
%to reference its value:
LET A=%A% + 1
%%as a prefix to reference the value from a variable, interchangeably:
LET A=%%A + 1
Use DOS batch's
ECHOto display output instead of BASIC's
ECHO Hello world
Support the standard DOS batch programming tests, such as
==to test equality, and
NOTto negate a test. Add extra constructs to test inequality, greater-than and less-than. One possible solution is to assume simple DOS batch programming
IFconstructs and use Unix-style brackets for the extra constructs:
IF ERRORLEVEL 0 ECHO Success
IF NOT ERRORLEVEL 0 ECHO Fail
IF EXIST FILE.TXT ECHO Exists
IF %VALUE%==1 ECHO Equal
IF NOT %VALUE%==1 ECHO Not equal
And it makes sense that brackets can be used for equivalent standard evaluation too (for example,
==). I'm using Fortran-style comparison operators here:
IF [ %VALUE% EQ 5 ] ECHO Equal
IF [ %VALUE% NE 5 ] ECHO Not equal
IF [ %VALUE% GT 5 ] ECHO Greater than
IF [ %VALUE% GE 5 ] ECHO Greater or equal
IF [ %VALUE% LT 5 ] ECHO Less than
IF [ %VALUE% LE 5 ] ECHO Less or equal
FORstatement would need to be extended as a for-next loop:
FOR N IN 1 TO 10
Or as the traditional DOS for-do one-line shortcut:
FOR N IN 1 TO 10 DO ECHO %N%
And add a special
IN (…)construct to create an iteration over a set, same as DOS batch:
FOR %%N IN (1 2 3 4 5 6 7 8 9 10) DO ECHO %%N
FOR %%F IN (*.TXT) DO ECHO %%F
(If the language allows
%%Afor single-letter variables, then DOS batch programs would probably work seamlessly. But it seems like sloppy coding here, because
%%appears as a variable name and a variable reference in DOS batch programming. Maybe restrict
%%to the special case of
IN (…)and only single-letter variables, to keep DOS batch compatibility Other ideas?)
Similar to both BASIC and DOS batch,
GOTOshould continue to use
:to mark labels:
LET N=%N% + 1
IF [ %N% LT 10 ] GOTO LOOP
And of course, comments remain the same from BASIC and DOS batch programming:
REM This is a comment
If you called the BASIC-like "shell" using a special parameter (like
/P) then it would be nice for anything else you specify that isn't recognized as a shell statement (assuming other syntax is correct) get treated like an external command. That would make this more like a shell:
IF EXIST FILE.TXT EDIT FILE.TXT
Also other internal constructs for
PATH, but you get the idea.
If you can preserve COMMAND.COM syntax and add a BASIC-like programming language behind it, that would make this an interesting extended shell. Maybe an idea for an interested developer?
for /L %%N in (1,1,10) do echo %%N(iterative loops) and
SET /A A=%%A + 1(arithmetic). So this hybrid BASIC-like batch programming language idea is not new.