Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 400
Phiber Avatar asked Feb 13 '14 21:02

Phiber


People also ask

How remove quotes of string in Batch?

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.

How do you remove quotes from a string?

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.

What is %% A in batch script?

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.


1 Answers

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.

like image 151
unclemeat Avatar answered Sep 22 '22 15:09

unclemeat