A useful feature in almost every command line environment is the environment variable. Some of these variables allow you to control the behavior or features of the command line, and other variables simply allow you to store useful data that you might need to reference later.
On Linux, you may already be familar with several of these important environment variables. In the Bash shell on Linux, the
PATH variable identifies where the shell can find programs and commands. For example, on my Linux system, I have this
bash$ echo $PATH /home/jhall/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin
That means when I type a command name like
cat, Bash will check each of the directories listed in my
PATH variable, in order:
And in my case, the
cat command is located in the
/usr/bin directory, so the full path to that command is
To set an environment variable on Linux, you type the name of the variable, then an "equals" sign (
=) and then the value to store in the variable. To reference that value later using Bash, you type a "dollar" sign (
$) in front of the variable name.
bash$ var=Hello bash$ echo $var Hello
On FreeDOS, environment variables serve a similar function. Some variables control the behavior of the DOS system, and others are useful to store some temporary value.
To set an environment variable on FreeDOS, you need to use the
SET keyword. FreeDOS is case insensitive, so you can type that using either uppercase or lowercase letters. Then set the variable as you might on Linux, using the variable name, an "equals" sign, and the value you want to store.
However, referencing or expanding an environment variable's value in FreeDOS is quite different from how you do it on Linux. You can't use the "dollar" sign to reference a variable in FreeDOS. Instead, you need to surround the variable's name with "percent" signs (
It's important to use the percent signs both before and after the name, because that's how FreeDOS knows where the variable name begins and ends. This is very useful, as it allows you to reference a variable's value while immediately appending (or prepending) other text to the value. Let me demonstrate this by setting a new variable called
reply with the value
yes, then referencing that value with the text "11" before and "22" after it:
Because FreeDOS is case insensitive you can also use uppercase or lowercase letters for the variable name, as well as the
SET keyword. However, the variable's value will use the letter case as you typed it on the command line.
Finally, you can see a list of all the environment variables currently defined in FreeDOS. Without any arguments, the
SET keyword will display all variables, so you can see everything at a glance:
Environment variables are a useful staple in command line environments, and the same applies to FreeDOS. You can set your own variables to serve your own needs, but be careful about changing some of the variables that FreeDOS uses. These can change the behavior of your running FreeDOS system:
|DOSDIR||The location of the FreeDOS installation directory, usually |
|COMSPEC||The current instance of the FreeDOS shell, usually |
|LANG||The user's preferred language|
|NLSPATH||The location of the system's language files, usually |
|TZ||The system's time zone|
|PATH||A list of directories where FreeDOS can find programs to run, such as |
|HELPPATH||The location of the system's documentation files, usually |
|TEMP||A temporary directory where FreeDOS stores output from each command as it "pipes" data between programs on the command line|
|DIRCMD||A variable that controls how the |
If you accidentally change any of the FreeDOS "internal" variables, you could prevent some parts of FreeDOS from working properly. In that case, simply reboot your computer, and FreeDOS will reset the variables from the system defaults.