powershell - 如何防止使用ansible在字符串中添加额外的双引号?
问题描述
以下注册表值具有用双引号括起来的路径。
win_shell: |
$((Get-ItemProperty HKLM:Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | `
where { $_.DisplayName -match '{{product_name}}' }).UninstallString) -split " -"
register: out
卸载字符串值如下(带双引号)
"C:\Program Files (x86)\InstallShield Installation Information\{584775F9-1696-4387-AEB5-86171F6567CC}\Setup-x64.5.0.1.8009.exe"
当我将结果分配给 set_fact 时,它会在字符串中再添加一个双引号。
- set_fact: uninstall_filePath="{{out.stdout_lines.0}}"
- debug: var=uninstall_filePath
ok: [Myremotehost] => {
"uninstall_filePath": "\"C:\\Program Files (x86)\\InstallShield Installation Information\\{584775F9-1696-4387-AEB5-86171F6567CC}\\Setup-x64.5.0.1.8009.exe\""
}
由于这个额外的双引号,我无法使用此路径进行卸载。如何从字符串中删除双引号?或者如何防止在字符串中添加一个额外的双引号?
解决方案
我认为您必须同时使用双引号和单引号。像这样的东西:
"'this is a string'"
只是玩这些或替代尝试转义字符
\
推荐阅读
- javascript - js对特殊字符的utf字符串进行条件测试
- r - 如果循环 - 参数长度为零 - 错误
- c# - 错误 CS0029:无法将类型“System.DateTime”隐式转换为“int”(CS0029)(DeclaringConstructor)
- reactjs - 物品清单,批量操作样本
- kubernetes - 如何在 values.yaml 中选择入口控制器
- asp.net-web-api2 - ASP.NET Core Web API 中是否存在像 AcceptRequestType 这样的东西?
- javascript - 避免将旧版 JavaScript 提供给现代浏览器
- c++ - 错误 C2248:“CObject::CObject”:当我在 MFC 中调用 hDC.SelectObject 函数时,无法访问在“CObject”类中声明的私有成员
- linux - 具有不同用户的外部驱动器的权限
- c++ - 如何修复(避免)“无调试信息”警告?