How to Access Environment Variables in an MS-DOS Batch File
IF "%VARIABLE%" == "" GOTO MODULEThis example checks for the existence of the environment variable"VARIABLE." If VARIABLE does not exist, the statement is true and controlof the batch file jumps to the MODULE section. If the statement is nottrue, that is, the VARIABLE variable does exist, program control skips tothe next line of the batch file and continues.
NOTE: The quotation marks are necessary only when a variable is used in alogical IF statement.
The following example illustrates the use of the PATH environment variablewithin a batch file:
IF "%PATH%" == "" GOTO NOPATH :YESPATH @ECHO The PATH environment variable was detected. PATH=C:\DOS;%PATH% GOTO END :NOPATH @ECHO The PATH environment variable was NOT detected. PATH=C:\DOS; GOTO END :ENDThis example tests for the existence of the PATH variable. If it exists,control passes to the YESPATH section; otherwise, control is passed to theNOPATH section.
If a path is detected and control is passed to the YESPATH section, C:\DOSis added to the existing path by using the %PATH% variable.
Αναγνωριστικό άρθρου: 121170 - Τελευταία αναθεώρηση: 09/30/2003 12:39:00 - Αναθεώρηση: 3.0