The environment is the variable storage area of the DOS system. It is stored in Ram and is the place where the DOS system stores important information for batch processing files. You can modify or modify the information as needed. Many dos reference books ignore it, but in any case, users are consciously or unconsciously using it.
How to Set and view the environment
There are two methods to access the environment: one is to view through the set command, and the other is to view the computer's Ram using the DEBUG command of the dossystem. The SET command is intuitive and convenient. Most users use it to set and view the DOS environment.
1. Use the SET command
The SET command can be used to set, modify, and view environment variables. You can enter a set command without parameters to display the current environment settings. These settings typically include the comspec and PATH environment variables that the MS-DOS uses to look for programs on disk. In addition, there are other environment variables used by the dossystem, such as prompt, dircmd, and copycmd. Most of these environment variables are generated by setting them with the set command in the autoexec. bat or config. SYS file. For example:
C:/> set
Comspec = C:/command. com
Prompt = $ p $ G
Path = C:/windows; C:/DOS; C:/foxpro25; C:/UCDOS; C:/gypc; C:/CCed; C: /HD; C:/sarp
Temp = C:/DoS
2. Run the DEBUG command
Debug is a powerful tool for debugging programs provided by DOS. It can be used to test original disk information, view memory units, disassemble program files, or generate new programs. However, debug commands are dangerous, therefore, you must pay attention to it during use.
Every program running in the DOS system generates a 256-byte memory block-the program segment prefix PSP (program segment prefix), which contains some important information, such as memory unit, vector, file name typed on the command line, command line itself, information about various reserved buffer storage locations. As long as the environment is involved, one of those storage locations will save the system environment address.
To view the environment in the DEBUG command status, first view the two bytes at the offset 2C:
-D2cl2
1b41: 0020 90 09
Data 90 09 is the segment address value of the computer environment obtained on a system (the actual number of display numbers should prevail during the operation). The order of the two pairs is the opposite, the system environment can be displayed on the DEBUG command after the offset is 0. For example:
-D0990: 0
0990: 0000 43 4f 4D 53 50 45 43 3d-43 3A 5C 43 4f 4D 41 comspec = C:/comma
0990: 0010 4E 44 2E 43 4f 4D 00 50-52 4f 4D 50 54 3D 24 70 nd. com. Prompt = $ P
0090: 0020 24 67 00 50 41 54 48 3d-43 3A 5C 57 49 4E 44 4f $ G. Path = C:/Windo
0990: 0030 57 53 3B 43 3A 5C 3B 43-3a 5C 44 4f 53 3B 43 3A ws; C: // C:/DOS; C:
0990: 0040 5C 46 4f 58 50 52 4f 32-35 3B 43 3A 5C 55 43 44/foxpro25; C:/UCD
0990: 0050 4f 53 3B 43 3A 5C 47 59-50 43 3B 43 3A 5C 43 43 OS; C:/gypc; C:/CC
0990: 0060 45 44 3B 43 3A 5C 48 44-3b 43 3A 5C 53 41 52 50 Ed; C:/HD; C:/sarp
0990: 0070 00 54 45 4D 50 3D 43 3a-5c 44 4f 53 00 01 00. Temp = C:/dos...
From the environment shown above, each item in the environment is separated by "null" Byte 00, and the last item in the environment is followed by two null characters.
The results of the Environment displayed by the preceding two methods are consistent.
Environment Variable
1. comspec variable
This variable specifies the location of the command. com file. Generally, if the computer is guided by a hard drive, the comspec variable is expressed:
Comspec = C:/command. com
If the boot is from a floppy drive, the comspec variable is:
Comspec = A:/command. com
Use the SET command to change the position of the comspec. The format is:
Set comspec = C:/DOS/command. com
This command re-sets comspec to the command. com file in the DOS directory of drive C in the system environment, because command. com does not need to be in the user's root directory. You can also put command. com into other sub-directories and use the shell command of config. sys to complete this work. Config. sys is in command. com. com is in another directory, the system goes to that directory to find it. This has an obvious advantage that it keeps the root directory clean.
In addition, to ensure normal system operation, you must add the following sentence in the con fig sys file:
Shell = C:/DOS/command. com/P [/E: 1024]
This command instructs DOS to search for and run the command interpreter or shell program command. com in the C:/DOS subdirectory. If you add this command to the config. SYS file, you can move command. com to the DOS subdirectory in advance. The P option indicates that command. com searches for the autoexec. BAT file in the root directory and runs it. If this option is not available, the autoexec. BAT file in the root directory cannot run.
When the DOS system does not have more storage environment variables, the following information is displayed:
Out of Environment Space (Environment Space overflow)
In this case, the shell command can be used to increase the environment space of command. com. The option E: 1024 is to expand the environment space to 1 kb (1024 bytes ).
2. Prompt variable
This environment variable displays the command prompt set by the user. The dossystem prompt is generally set to show the current drive and path followed by a ">" symbol, of course, you can also set to another type of command prompt, this variable is generally set in the autoexec BAT file, the command is generally in the following format:
Prompt $ p $ G
Of course, you can also use set prompt = $ p $ G.
3. PATH variable
This environment variable includes using the path command to set the path so that the DOS system can search for executable files in the specified directory.
4. dircmd variable
This environment variable allows you to determine the default switch and parameter set used by the Dir command. You can use the set command in the autoexec. BAT file or command prompt to define the dircmd environment variable, and set the valid combination of Dir parameters and options (including path and file name) in advance ).
For example, to set the dircmd environment variable to the default format when the screen is full (/P), type in the autoexec. bat batch file or doscommand prompt:
Set dircmd =/P
At this time, the Dir command will be paused when the screen is full and prompt "press any key to continue ".
If you do not want to use this default format, you can use it on the command line:
DIR/-P
To clear this default setting, type:
Set dircmd =
5. copycmd variable
You can set the copycmd environment variable to specify whether the copy, move, and xcopy commands give a prompt first, and then overwrite the file after confirmation.
If the copy, move, and xcopy commands are required, the following message is displayed in all cases:
Overwrite filename (Yes/No/All )?
Set the copycmd environment variable to/-y (set copycmd =/-y). You can choose whether to overwrite the environment variable as needed. You can also force the copy, move, and xcopy commands to overwrite without prompting in all cases. Then, set the copycmd environment variable to/Y (set copycmd =/Y ). The copycmd environment variables set here take precedence over all default values and current values of the copycmd environment variables.
6. Temp variable
Temp is a common environment variable that tells the program where to create a temporary file, while some programs need to use environment variables to identify the directories they want to use. For example:
Set temp = C:/DoS
In this example, the environment variable temp is used by the DOS environment and some other programs to determine the location of the subdirectory of the current file. The above directory c:/DOS is put into the environment. Now the DOS system knows where to put their current files. In the autoexec. BAT file, you can set the entire environment conversion.
Relationship between environment variables and batch files
Using environment variables can control certain batch files and allow programs to be performed as user-desired, and control the way the MS-DOS is displayed and operated. Generally, the set command is used in the autoexec bat or CONFIG sys file to set the user environment, so that the system can automatically set the environment variables according to user needs each time the computer is started.
1. Call the environment variable in the batch file
When you call the environment variable value from a batch file, you must use the percentile (%) to enclose the variable value. For example, if you set a variable named Win32 to make it equal to the string C:/Windows/system (directory in drive C), type the following command:
Set Win32 = C:/Windows/System
In the batch file, % Win32 % can be used to replace C:/Windows/system. Run the following command in the batch file to display the directory content of the C:/Windows/system environment variable:
Dir % Win32 %
When the MS-DOS processes this command, % Win32 % is replaced with the string C:/Windows/system.
2. Save and restore the path in the original environment in the batch file
For each batch file, you can modify the environment variables, and each batch file requires different paths to specify the path to execute the program under batch processing, this requires you to save the path in the original environment. You can use an environment variable in the batch file to temporarily store the original path of the user, so that it can be restored as needed, without the need to re-use the path command to set it:
Set oldpath = % PATH %
For example, a computer is configured as follows:
Set oldpath = C:/windows; C:/DOS; C:/foxpro25; C:/UCDOS; C:/gypc; C:/CCed; C: /HD; C:/sarp
The batch file interpreter extends the % PATH % variable to the current path of the user, so the oldpath variable is equal to this path. If the system breaks the original system path because other batch files are used, you can use the following statements to restore the original path in the batch files to meet your needs for different environments. For example:
PATH % oldpath %
The computer displays its execution status:
Path C:/windows; C:/DOS; C:/foxpro25; C:/UCDOS; C:/gypc; C:/CCed; C:/HD; c:/sarp
In fact, many users may have the "oldpath" variable in their autoexec BAT files. Because this environment variable always contains the backup of the original path, it is easy to restore the original path.
Summary
Environment is one of the most important aspects of the DOS system. It is a variable storage area used by the DOS system to store important information for batch files-a high-speed temporary storage. It stores important information and puts the environment variables of the batch file into it.
The SET command is very important to the environment. It is used to assign values to variables, clear variables, and display environment content.
In addition to the location of command com given by the environment variable (comspec) generated by the user, path sets the system search path; prompt sets the system prompt; the copycmd environment variable specifies whether the copy, move, and xcopy commands prompt the files to be overwritten. The dircmd environment variable can be used to preset the Dir parameter and switch item.
Because the environment table is quite small, shell commands can be used to expand its capacity. This avoids the error of "out of Environment Space, but it also occupies the system's Ram.