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
Double quotes can be removed from variables in a Batch file using the tilde ( ~ ) character. The tilde ( ~ ) character is used in many ways in Batch files. Apart from being an argument quote removal, it is also used to extract a substring from a string variable in a Batch file.
Use the String. replaceAll() method to remove all double quotes from a string, e.g. str. replaceAll('"', '') . The replace() method will return a new string with all double quotes removed.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With