【发布时间】:2021-10-09 18:48:35
【问题描述】:
在 Power shell 中,我尝试运行 ORacle Cloud CLI 命令并使用 JQ 对其进行过滤。 如果我在 JQ select 中使用硬编码值,它工作正常..但如果我使用变量,我不会得到任何数据。请帮忙。
在选择中使用硬编码值:
oci compute instance list-vnics --all --compartment-id xxxxx --profile myprof |C:\myfiles\jq-win64.exe '.data[]|select(.\"hostname-label\"==\"test1\")'
选择中带有变量的失败代码:
oci compute instance list-vnics --all --compartment-id xxxxx --profile myprof |C:\myfiles\jq-win64.exe '.data[]|select(.\"hostname-label\"==\"$host_name\")'
【问题讨论】:
-
简而言之:只有
"..."字符串(双引号)在 PowerShell 中执行字符串插值(变量值的扩展),而不是'...'字符串(单引号):请参阅 this answer PowerShell 的可扩展字符串(插值字符串)概述和this answer 概述 PowerShell 字符串文字的一般概述。
标签: powershell oracle-cloud-infrastructure