Command: Environment Variables

  Environment variable is no direct command but part of
  COMMAND.COM / FREECOM.COM.

Syntax:

  - none

Options:

 - none -

Comments:

  Environment variables can be freely assigned using the SET command,
  e.g. executing:
    SET var1=tecxsgk;jsdgsdflfsjdflkasjf/lasjflas
  assigns this nonsense to the variable var1. Later on, the
  value of the variable can be used by writing: %var1%, thus, writing
  the name of the variable enclosed without whitespace by two percent
  signs.
  Warning: Environment variables are expanded fully into plain
  text before the command line is furtherly parsed. If a variable
  contains an odd number of quotes, the remaining command line must
  contain the closing quote in order to operate properly. Also see this:
    SET var=text del
    IF text==%var% GOTO label
  The second line looks uninteresting, but once the environment variable
  has been expanded the line has morphed into:
    IF text==text del GOTO label
  not that funny anymore, because the IF command interpretes only the
  string text==text as condition, but del GOTO label is executed
  as command.

  FreeCOM uses a number of environment variables for its own purpose.
  - COMSPEC: FreeCOM loads some information on demand, these data
    are stored in the FreeCOM executable. The value of this environment
    variable contains the filename FreeCOM shall use. The contents can
    be changed with the SET command.
  - DIRCMD: The user may define default values for the
    DIR command. Any options specified within DIRCMD are prefixing
    any entered ones, so to say FreeCOM behaves as if the user always
    types:
      DIR %DIRCMD% «other arguments»
    This variable must be changed using the SET command.
  - COPYCMD: This variable contains default options for the COPY
    command.
  - PROMPT: FreeCOM prompts the user to enter commands to run,
    the PROMPT can be customized by changing the contents of this
    variable.
    This variable can be changed using the SET or the PROMPT commands.
    Latter one includes a detailed description of the format of the
    PROMPT string.
  - PATH: When FreeCOM is to execute an external command and this
    one does not contain no path, FreeCOM searched for the command in a
    number of paths. These ones are enumerated by the PATH environment
    variable.
    This variable can be changed using the SET or the PATH commands.
    Latter one includes a detailed description of the format of the
    search path.

  There are a number of automatic variables that do not follow the above
  mentioned syntax and which contents is automatically generated. Unlike
  the normal variables these automatic variables are constructed of
  exactly two characters, the first one is a single percent sign and the
  second one the variable identifier:
  - %?: expands to the current ERRORLEVEL, which is the exit code of
    the previously executed external command.
  - %0: in BATCH SCRIPTS only: is the name of the script currently
    executed.
  - %1 through %9: in BATCH SCRIPTS only: are the first through nineth
    argument passed to the currently executed batch script. If less than
    nine arguments had been passed to the script, they return an empty
    string. To access the tenth argument please refer to the SHIFT
    command.
  - FOR %v IN (...) DO «any command»: %v may use any letter,
    the FOR command creates a new variable, which is valid in the
    «any command» following the DO keyword.
  - %%: Is no real variable, but expands to a single percent sign.

  Because automatic variables have one percent sign only, it sometimes lead to
  confusion within the FOR command, e.g. in:
    SET adam=eva
    FOR %a in (*.*) DO echo %adam% %a
    %adam is interpreted as [%a]dam.

Examples:

  SHELL=C:\FREEDOS\BIN\COMMAND.COM C:\FREEDOS\BIN /P=C:\FDAUTO.BAT
           /E:1024 OR:
  SHELLHIGH=C:\FREEDOS\BIN\COMMAND.COM C:\FREEDOS\BIN /P=C:\FDAUTO.BAT
           /E:1024
  /P       Loads command.com permanently
  /E:1024  Sets the initial environment size to 1024 Bytes
           Standard size is 256 Bytes)
  When command.com is loaded, the environment variable exists and you
  can use it via command line or batch file. E.g.:
  set path=C:\FREEDOS\BIN, C:\
  prompt $p$g
  memory   Shows size and used space of Environment variable

See also:

  alias
  batch scripts
  cd/chdir
  command.com/freecom
  dirs
  errorlevel
  for
  history
  mem
  memory
  path
  popd
  prompt
  pushd
  set

  Copyright © 2006 the FreeDOS command.com team, adapted to
  FreeDOS help in 2022 by W. Spiegl.

  This file is derived from the FreeDOS Spec Command HOWTO.
  See the file H2Cpying for copying conditions.