Understanding and Accessing DOS Environment Variables
Environment variables are the variable storage area of the DOS system, a high-speed temporary storage space kept in RAM. It is where the DOS system stores important information for batch files to use. In DOS, we are using environment variables all the time.
Generally, they can be handled in two ways, as follows:
1. Using the SET command. To access the environment, the SET command can be used to set, customize, and view environment variables. Entering SET with no parameters will display the current environment settings. These settings generally include the COMSPEC and PATH environment variables, which MS-DOS uses to look for programs on disk. In addition, there are other environment variables used by the DOS system, such as PROMPT, DIRCMD, and COPYCMD. Most of these environment variables are created by being set with the SET command in the AUTOEXEC.BAT or CONFIG.SYS files.
2. Through the DEBUG command. DEBUG is a powerful tool among the debugging programs provided by DOS. It can be used to examine raw disk information, view memory units, disassemble program files, or create new programs, and so on. However, the DEBUG command has a certain degree of danger, so users should be careful while using it.
Each time the DOS system runs a program, it creates a 256-byte memory block called the Program Segment Prefix, or PSP. It contains some relatively important information, such as memory units, vectors, the file name entered on the command line, the command line itself (a copy of the command line the user used to run the program), and information on the storage locations of various reserved buffers. As long as the environment is involved, one of those storage locations will hold the address of the system environment.
In DOS, there are generally six commonly used environment variables. The specific explanation of these six variables is as follows:
1. The COMSPEC variable. This variable specifies the location of the COMMAND.COM file. Usually, if the computer is booted from the hard drive, the COMSPEC variable is shown as “COMSPEC=C:\COMMAND.COM”; if it is booted from the floppy drive, then the COMMSPEC variable is shown as “COMSPEC=A:\COMMAND.COM”.
The SET command can change the location of COMSPEC. Its format is “SET COMSPEC=C:\DOS\COMMAND.COM”. This command resets COMSPEC in the system environment to the COMMAND.COM file in the DOS directory on drive C, because COMMAND.COM does not need to be in the user's root directory. The user can also put COMMAND.COM into another subdirectory and use the SHELL command in CONFIG.SYS to do this. During the computer's startup process, CONFIG.SYS is run before COMMAND.COM is loaded. If the SHELL command tells the DOS system that COMMAND.COM is in another directory, then the system will go to that directory to find it. This has one obvious advantage: it keeps the root directory clean.
In addition, to ensure that the system can run properly, the user also needs to add the command “SHELL=C:\DOS\COMMAND.COM/” to the CONFIG.SYS file. This command tells DOS to look in the C:\DOS subdirectory for the command interpreter, or shell program, COMMAND.COM, and run it. If this command is added to the CONFIG.SYS file, COMMAND.COM can be moved into the DOS subdirectory in advance. The P option tells COMMAND.COM to look for the AUTOEXE.BAT file in the root directory and run it. Without this option, the AUTOEXEC.BAT file in the root directory cannot be run. When the DOS system no longer has enough space to store environment variables, you will see the message “Out of environment space”. When this happens, the SHELL command can be used to enlarge the environment space of COMMAND.COM. The optional E:1024 expands the environment space to 1KB (1024 bytes).
2. The PROMPT variable. This environment variable displays the command prompt set by the user. The DOS system prompt is generally set to display the current drive and path followed by a “>” symbol. Of course, it can also be set to other types of command prompts. This variable is generally set in the AUTOEXEC.BAT file, and the usual command format is “PROMPT $p$g”. Of course, you can also use the command “SET PROMPT=$p$g”.
3. The PATH variable. This environment variable includes the path set with the PATH command, enabling the DOS system to search for executable files in the specified directories.
4. The DIRCMD variable. This environment variable lets the user specify the default parameter and switch set used by the DIR command. The user can define the DIRCMD environment variable with the SET command either in the AUTOEXEC.BAT file or at the command prompt, pre-setting a legal combination of DIR parameters and options (which may include paths and file names).
For example, if you want to set the DIRCMD environment variable so that pausing at each full screen (/P) is the default format, enter “SET DIRCMD=/P” in the AUTOEXEC.BAT batch file or at the DOS command prompt. Then when using the DIR command, it will pause when one screen is full and prompt “Press any key to continue”. If you do not want to use this default format, you can use “DIR /-P” on the command line. If you want to clear this default setting, enter the command “SET DIRCMD=” at the command prompt.
5. The COPYCMD variable. By adjusting the COPYCMD environment variable, you can specify whether the COPY, MOVE, and XCOPY commands should first give a prompt and overwrite the file only after confirmation. If you want to force COPY, MOVE, and XCOPY to always first give the prompt “Overwrite Filename(YES/NO/ALL)?” in all cases, just set the COPYCMD environment variable to /-Y (SET COPYCMD=/-Y), and the user can then choose as needed whether to overwrite. It can also be forced so that COPY, MOVE, and XCOPY overwrite in all cases without prompting, by setting the COPYCMD environment variable to /Y (SET COPYCMD=/Y). The COPYCMD environment variable set here takes precedence over all default and current values of the COPYCMD environment variable.
6. The TEMP variable. TEMP is a commonly used environment variable. It tells programs where to create temporary files, and some programs need to use environment variables to identify the directory they should use. For example, “SET TEMP=C:\DOS”. Here the TEMP environment variable is used by the DOS environment and some other programs to determine the location of the current file subdirectory. The above directory C:\DOS is placed into the environment, and now the DOS system knows where to put their current files. In the AUTOEXEC.BAT file, the user can and should also set the entire environment conversion.
Environment variables are the variable storage area of the DOS system, a high-speed temporary storage space kept in RAM. It is where the DOS system stores important information for batch files to use. In DOS, we are using environment variables all the time.
Generally, they can be handled in two ways, as follows:
1. Using the SET command. To access the environment, the SET command can be used to set, customize, and view environment variables. Entering SET with no parameters will display the current environment settings. These settings generally include the COMSPEC and PATH environment variables, which MS-DOS uses to look for programs on disk. In addition, there are other environment variables used by the DOS system, such as PROMPT, DIRCMD, and COPYCMD. Most of these environment variables are created by being set with the SET command in the AUTOEXEC.BAT or CONFIG.SYS files.
2. Through the DEBUG command. DEBUG is a powerful tool among the debugging programs provided by DOS. It can be used to examine raw disk information, view memory units, disassemble program files, or create new programs, and so on. However, the DEBUG command has a certain degree of danger, so users should be careful while using it.
Each time the DOS system runs a program, it creates a 256-byte memory block called the Program Segment Prefix, or PSP. It contains some relatively important information, such as memory units, vectors, the file name entered on the command line, the command line itself (a copy of the command line the user used to run the program), and information on the storage locations of various reserved buffers. As long as the environment is involved, one of those storage locations will hold the address of the system environment.
In DOS, there are generally six commonly used environment variables. The specific explanation of these six variables is as follows:
1. The COMSPEC variable. This variable specifies the location of the COMMAND.COM file. Usually, if the computer is booted from the hard drive, the COMSPEC variable is shown as “COMSPEC=C:\COMMAND.COM”; if it is booted from the floppy drive, then the COMMSPEC variable is shown as “COMSPEC=A:\COMMAND.COM”.
The SET command can change the location of COMSPEC. Its format is “SET COMSPEC=C:\DOS\COMMAND.COM”. This command resets COMSPEC in the system environment to the COMMAND.COM file in the DOS directory on drive C, because COMMAND.COM does not need to be in the user's root directory. The user can also put COMMAND.COM into another subdirectory and use the SHELL command in CONFIG.SYS to do this. During the computer's startup process, CONFIG.SYS is run before COMMAND.COM is loaded. If the SHELL command tells the DOS system that COMMAND.COM is in another directory, then the system will go to that directory to find it. This has one obvious advantage: it keeps the root directory clean.
In addition, to ensure that the system can run properly, the user also needs to add the command “SHELL=C:\DOS\COMMAND.COM/” to the CONFIG.SYS file. This command tells DOS to look in the C:\DOS subdirectory for the command interpreter, or shell program, COMMAND.COM, and run it. If this command is added to the CONFIG.SYS file, COMMAND.COM can be moved into the DOS subdirectory in advance. The P option tells COMMAND.COM to look for the AUTOEXE.BAT file in the root directory and run it. Without this option, the AUTOEXEC.BAT file in the root directory cannot be run. When the DOS system no longer has enough space to store environment variables, you will see the message “Out of environment space”. When this happens, the SHELL command can be used to enlarge the environment space of COMMAND.COM. The optional E:1024 expands the environment space to 1KB (1024 bytes).
2. The PROMPT variable. This environment variable displays the command prompt set by the user. The DOS system prompt is generally set to display the current drive and path followed by a “>” symbol. Of course, it can also be set to other types of command prompts. This variable is generally set in the AUTOEXEC.BAT file, and the usual command format is “PROMPT $p$g”. Of course, you can also use the command “SET PROMPT=$p$g”.
3. The PATH variable. This environment variable includes the path set with the PATH command, enabling the DOS system to search for executable files in the specified directories.
4. The DIRCMD variable. This environment variable lets the user specify the default parameter and switch set used by the DIR command. The user can define the DIRCMD environment variable with the SET command either in the AUTOEXEC.BAT file or at the command prompt, pre-setting a legal combination of DIR parameters and options (which may include paths and file names).
For example, if you want to set the DIRCMD environment variable so that pausing at each full screen (/P) is the default format, enter “SET DIRCMD=/P” in the AUTOEXEC.BAT batch file or at the DOS command prompt. Then when using the DIR command, it will pause when one screen is full and prompt “Press any key to continue”. If you do not want to use this default format, you can use “DIR /-P” on the command line. If you want to clear this default setting, enter the command “SET DIRCMD=” at the command prompt.
5. The COPYCMD variable. By adjusting the COPYCMD environment variable, you can specify whether the COPY, MOVE, and XCOPY commands should first give a prompt and overwrite the file only after confirmation. If you want to force COPY, MOVE, and XCOPY to always first give the prompt “Overwrite Filename(YES/NO/ALL)?” in all cases, just set the COPYCMD environment variable to /-Y (SET COPYCMD=/-Y), and the user can then choose as needed whether to overwrite. It can also be forced so that COPY, MOVE, and XCOPY overwrite in all cases without prompting, by setting the COPYCMD environment variable to /Y (SET COPYCMD=/Y). The COPYCMD environment variable set here takes precedence over all default and current values of the COPYCMD environment variable.
6. The TEMP variable. TEMP is a commonly used environment variable. It tells programs where to create temporary files, and some programs need to use environment variables to identify the directory they should use. For example, “SET TEMP=C:\DOS”. Here the TEMP environment variable is used by the DOS environment and some other programs to determine the location of the current file subdirectory. The above directory C:\DOS is placed into the environment, and now the DOS system knows where to put their current files. In the AUTOEXEC.BAT file, the user can and should also set the entire environment conversion.
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos



