{"id":14044,"date":"2026-06-08T03:00:00","date_gmt":"2026-06-08T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14044"},"modified":"2026-05-04T16:37:50","modified_gmt":"2026-05-04T20:37:50","slug":"using-variables-in-freedos","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14044","title":{"rendered":"Using variables in FreeDOS"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14044\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">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 data that you might need to reference later. Environment variables are also used in FreeDOS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"variables-on-linux\">Variables on Linux<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On Linux, you may already be familiar with several of these important environment variables. In the Bash shell on Linux, the <code>PATH<\/code> variable identifies where the shell can find programs and commands. For example, on my Linux system, I have this <code>PATH<\/code> value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash$ echo $PATH\n\/home\/jhall\/bin:\/bin:\/usr\/bin:\/usr\/local\/bin<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That means when I type a command name like <strong>cat<\/strong>, Bash will check each of the directories listed, in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\/home\/jhall\/bin<\/li>\n\n\n\n<li>\/bin<\/li>\n\n\n\n<li>\/usr\/bin<\/li>\n\n\n\n<li>\/usr\/local\/bin<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">And in my case, the <strong>cat<\/strong> command is located in the <code>\/bin<\/code> directory. (Actually, Fedora Linux merged the <code>\/bin<\/code> and <code>\/usr\/bin<\/code> directories a while ago, so my <code>PATH<\/code> is actually an anachronism. But I keep it that way because it&#8217;s still <em>technically correct<\/em>, which is the best kind of correct.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash$ var=Hello\nbash$ echo $var\nHello<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"variables-on-freedos\">Variables on FreeDOS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To set an environment variable on FreeDOS, you need to use the <code>SET<\/code> 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, referencing or expanding an environment variable&#8217;s value in FreeDOS is quite different from how you do it on Linux. You can&#8217;t use the dollar sign ($) to reference a variable in FreeDOS. Instead, you need to surround the variable&#8217;s name with percent signs (%).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\&gt;echo %PATH%\nC:\\freedos\\bin<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s important to use the percent signs both before and after the name because that&#8217;s how FreeDOS knows where the variable name begins and ends. This is very useful, as it allows you to reference a variable&#8217;s value while immediately appending (or prepending) other text to the value. Let me demonstrate this by setting a new variable called <code>REPLY<\/code> with the value <code>yes<\/code>, then referencing that value with the text &#8220;11&#8221; before and &#8220;22&#8221; after it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\&gt;set REPLY=yes\nC:\\&gt;echo 11%REPLY%22\n11yes22<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because FreeDOS is case insensitive you can also use uppercase or lowercase letters for the variable name, as well as the <code>SET<\/code> keyword. However, the variable&#8217;s value will use the letter case as you typed it on the command line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, you can see a list of all the environment variables currently defined in FreeDOS. Without any arguments, the <code>SET<\/code> keyword will display all variables, so you can see everything at a glance:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\&gt;set\nCONFIG=2\nDOSDIR=C:\\FreeDOS\nCOMSPEC=C:\\FreeDOS\\BIN\\COMMAND.COM\nPATH=C:\\freedos\\bin\nTEMP=C:\\freedos\\temp\nTMP=C:\\freedos\\temp\nLANG=en\nNLSPATH=C:\\freedos\\nls\nHELPPATH=C:\\freedos\\help\nTZ=utc\nDIRCMD=\/O:GNE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DOSDIR<\/code> &#8211; The location of the FreeDOS installation directory<\/li>\n\n\n\n<li><code>COMSPEC<\/code> &#8211; The current instance of the FreeDOS shell<\/li>\n\n\n\n<li><code>LANG<\/code> &#8211; The user&#8217;s preferred language<\/li>\n\n\n\n<li><code>NLSPATH<\/code> &#8211; The location of the system&#8217;s language files<\/li>\n\n\n\n<li><code>TZ<\/code> &#8211; The system&#8217;s time zone (not used by DOS, but some programs complain if it&#8217;s not there)<\/li>\n\n\n\n<li><code>PATH<\/code> &#8211; A list of directories where FreeDOS can find programs to run<\/li>\n\n\n\n<li><code>HELPPATH<\/code> &#8211; The location of the system&#8217;s documentation files<\/li>\n\n\n\n<li><code>TEMP<\/code> &#8211; A temporary directory where FreeDOS stores output from each command as it &#8220;pipes&#8221; data between programs on the command line<\/li>\n\n\n\n<li><code>DIRCMD<\/code> &#8211; A variable that controls how the DIR command displays files and directories, such as <code>\/O:GNE<\/code> to order (O) the contents by grouping (G) directories first, then sorting entries by name (N) then extension (E)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If you accidentally change any of the FreeDOS &#8220;internal&#8221; 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.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Adapted from <a href=\"https:\/\/opensource.com\/article\/21\/6\/freedos-environment-variables\">Set and use environment variables in FreeDOS<\/a> by Jim Hall<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Environment variables are helpful in almost every command-line environment, including FreeDOS<\/p>\n","protected":false},"author":33,"featured_media":4314,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[100,340],"tags":[104,963,267],"class_list":["post-14044","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-freedos","tag-command-line","tag-environment-variables","tag-freedos"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14044"}],"version-history":[{"count":4,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14044\/revisions"}],"predecessor-version":[{"id":14062,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14044\/revisions\/14062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/4314"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}