A system administrator is reviewing an automated legacy maintenance batch script (`.bat`) designed to run natively in the Windows Command Prompt environment. The script must check if a custom environment variable named `ARCHIVE_PATH` has been defined before attempting to move log files to that destination. Which of the following code constructs uses the correct syntax to evaluate this environment variable inside a Windows batch script?
- IF "%ARCHIVE_PATH%"=="" (ECHO Archive path is not specified)Cevap
- BIF "$env:ARCHIVE_PATH"=="" (ECHO Archive path is not specified)
- CIF "$ARCHIVE_PATH"=="" (ECHO Archive path is not specified)
- DIF "WScript.CreateObject(ARCHIVE_PATH)"=="" (ECHO Archive path is not specified)
Cevap
The statement using the `%ARCHIVE_PATH%` syntax correctly references environment variables within a Windows batch (`.bat`) conditional statement.
In standard Windows Command Prompt batch scripts (`.bat`), environment variables are accessed by surrounding the variable name with percent signs, such as `%ARCHIVE_PATH%`. When placed inside an `IF` condition, string quotes ensure that empty or unassigned variables do not trigger command parser syntax errors.
Adım Adım Çözüm
Anahtar Kavram
Windows Batch Scripting Environment Variable Syntax