首页 > 解决方案 > 从批处理文件执行powershell命令时转义双引号

问题描述

我必须在 PowerShell 命令中使用正则表达式替换命令。替换为 RegEx 仅适用于双引号 (")。此外,要在批处理文件中执行 PowerShell 命令,该命令必须在双引号 (") 内,如下所示:

powershell -command ""

那么,有没有办法逃避与替换命令一起使用的双引号,因为以下由于双引号冲突而引发错误:

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

我试过使用 (`) 像:

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

有人可以提出一些解决方案吗?

标签: windowspowershellbatch-filecommandescaping

解决方案


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


推荐阅读