Removing double quotes from variables in batch file creates problems with CMD environment

前端 未结 11 589
春和景丽
春和景丽 2020-12-04 11:25

Can anybody help with effective and safe way of removing quotes from batch variables?

I have written a batch file which successfully imports a list of parameters %1,

11条回答
  •  不知归路
    2020-12-04 11:39

    @echo off
    
    Setlocal enabledelayedexpansion
    
    Set 1=%1
    
    Set 1=!1:"=!
    
    Echo !1!
    
    Echo "!1!"
    
    Set 1=
    

    Demonstrates with or without quotes reguardless of whether original parameter has quotes or not.

    And if you want to test the existence of a parameter which may or may not be in quotes, put this line before the echos above:

    If '%1'=='' goto yoursub

    But if checking for existence of a file that may or may not have quotes then it's:

    If EXIST "!1!" goto othersub

    Note the use of single quotes and double quotes are different.

提交回复
热议问题