简体   繁体   中英

Escaping double quotes while executing powershell commands from batch file

I have to use replace command with regex in the PowerShell command. Replace with RegEx works only with double quotes ("). Also to execute the PowerShell command in batch file, the command must be inside double quotes (") like this:

powershell -command ""

So, is there a way to escape the double quotes used with the replace command as the below is throwing error because of conflict in double quotes:

powershell -command "$content -replace ",$", ",NULL""

I have tried using (`) like:

powershell -command "$content -replace `",$`", `",NULL`""

Could anyone please suggest some solution?

Use twice the double quote symbol (ie "") to escape it in PowerShell.

echo "Here is my ""double quoted"" test."

This will print: Here is my "double quoted" test.

Did you try something like:

-command "$content -replace "",$"", "",NULL"""

这是一个迟到的响应,但是您可以在双引号之间使用'引号,然后您可以这样写: powershell -command "$content -replace ',$', ',NULL'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM