Search code examples
windowsbatch-file

remove quotes "" from string in batch file


I use:

FOR /F "delims=" %%G IN ("%command%") DO SET command=%%~G

to remove "" quotes from variable %command%. If command = "Shutdown /s /t 00", after this line it will be: Shutdown /s /t 00. and it works. But when command contains a string where are a equal sign (=), it remove also this caracter. Example:
before, command = "D:\temp\stinger --ADL --GO --Silent --ReportPath= D:\temp --ReportOnly --Delete --Program"
After, command= D:\temp\stinger --ADL --GO --Silent --ReportPath D:\temp --ReportOnly --Delete --Program

Look, the quotes "" are removed, but also the sign = .

So, how to remove the quotes "" without removing the equal character.

Thanks


Solution

  • Instead of your for loop through the command, you could just use string manipulation.

    set command=%command:"=%
    

    the values after command are "=<nul> so you're getting rid of quotation marks in the variable command. Just as an extra example, you could also do %command: =_% to replace all spaces in command with underscores.