Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape "double quotes" inside batch's input parameters

Tags:

I want to run the following in batch script where it takes an argument (a path)

runas /user:abc "icacls %1 /grant Everyone:(F) /T" 

but the argument %1 already contains a " (because it's a path, passed on by context menu's Send To - I don't have much control over this). So when the command runs in batch script it runs like this:

runas /user:abc "icacls "c:\folder" /grant Everyone:(F) /T" 

So obviously I need to escape the "s created by %1. How do I perform string manipulation over %1 such that it escaped the quotes?

like image 428
laggingreflex Avatar asked Aug 09 '12 23:08

laggingreflex


People also ask

How can I escape a double quote inside double quotes?

' appearing in double quotes is escaped using a backslash. The backslash preceding the ' !

How do you pass a parameter in a double quote?

Escape every double quote " with a caret ^ . If you want other characters with special meaning to the Windows command shell (e.g., < , > , | , & ) to be interpreted as regular characters instead, then escape them with a caret, too.

How do you escape double quotes from value of JSON field?

if you want to escape double quote in JSON use \\ to escape it.

How do you ignore a double quote in a string?

This method replaces all parts of the String that match a given regular expression. Using replaceAll, we can remove all occurrences of double quotes by replacing them with empty strings: String result = input. replaceAll("\"", "");


1 Answers

You should be able to use \" Here is a site with a few other escape characters that you might find useful

To perform the string replace:

set temp=%1 set temp=%temp:"=\"% echo %temp% 
like image 149
nick Avatar answered Oct 19 '22 08:10

nick