Thursday, July 12, 2018

FreeDOS batch programming quick reference

A few weeks ago, I posted a "quick reference" for our new users. This reference showed the most common FreeDOS commands, including a few important notes for new users.

If you're looking to take the next step in FreeDOS, here's a handy quick reference guide to batch programming.

DOS batch programs are simple scripts that "batches up" several commands into one file. Batch programs have some basic flow control that you can use to do loops and jump to different segments of the program. In batch programs, reference variable values by enclosing the variable name with %, such as %PATH%

What do you want to do?How to do it in a batch program:
Execute another batch script from within a scriptCALL SCRIPT.BAT
Run a command for each file in a listFOR %%F IN (*.TXT) DO EDIT %%F

or at the command line:

The loop variable name can only be one character.
Print a messageECHO Hello world
Jump to a label in a batch file:LOOP
Test the value of a stringIF %VAR%==Y ECHO Yes
Test if a file existsIF EXIST TEMP.DAT DEL TEMP.DAT
Test the return value of the previous commandIF ERRORLEVEL 0 ECHO Success
Test the oppositeIF NOT ERRORLEVEL 0 ECHO Fail
Set the shell's search path for programsPATH C:\FDOS\BIN;C:\MY\BIN

or to reference the existing path:

Use ; to separate paths.
Shift the command line optionsSHIFT or SHIFT 1 or any n

Reference command line options as %1, %2, and so on.
A commentREM This is a comment


  1. very nice, would be cool, if there a "search a string in the text.txt and change the value behind "[this entry]" \n settings=blabla to settings=totalokey "

    this could be helpful in autoexec/config or other textfiles


  2. You are describing steam editing. You can do some of that using edlin. Or you can use GNU awk from the gnuish utilities to do exactly what you describe. In gawk, it's pretty straightforward to detect a string in a file, use that as a marker to modify a matching line that follows. You can get gawk here: