Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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."
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading