Escaping dot in if-statement with echo in Windows batch

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!

>Solution :

I found the answer in another SO question.

@echo|set /p="Please install 7-Zip or 7-Zip-ZStandard and try again."

Leave a Reply