I have a chicken-and-egg issue: I need to echo a dot in an if statement in a batch script, but the command prompt crashes, saying '. was unexpected at this time.'
Note that echoing treats everything as literal, but the if statement interprets it as incorrect due to the dot being a special character.
Adding quotation marks solves the issue, but I don't want the batch user to see the error with quotation marks. I've tried using the caret ^ character to escape it, but it's not working.
Here's my script:
if "%found_7zip%"=="0" (
echo 7-Zip or 7-Zip-ZStandard not found in Program Files or Program Files (x86).
echo Please install 7-Zip or 7-Zip-ZStandard and try again.
pause
exit /b 1
)
Your help is appreciated! Thank you!
The solution is to escape the closing parenthesis.
This is necessary, because the opening parenthesis in
if "%found_7zip%"=="0" (starts the scanning for the first closing parenthesis, independent of the position in a line.It can escaped by a caret or by double quotes