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?
' appearing in double quotes is escaped using a backslash. The backslash preceding the ' !
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.
if you want to escape double quote in JSON use \\ to escape it.
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("\"", "");
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%
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