【发布时间】:2021-10-10 04:06:31
【问题描述】:
我试图使用 JQ 解析 OCI JSON 输出并在 Windows powershell 中出现语法错误,但是相同的命令在 Bash 终端中运行良好。 如果我遗漏了什么,请告诉我。
PS C:\myfiles> oci compute instance list-vnics --all --compartment-id xxxxxx --profile myprof |C:\myfiles\jq-win64.exe ".data[]|select(."hostname-label"=="test1" )"
jq: error: syntax error, unexpected $end, expecting ';' or ')' (Windows cmd shell quoting issues?) at <top-level>, line 1: .data[]|select(. jq: 1 compile error PS C:myfiles>
尝试使用单引号中的 JQ 语句,它给出以下语法错误:
PS C:\myfiles> oci compute instance list-vnics --all --compartment-id xxxxx --profile myprof |C:\myfiles\jq-win64.exe '.data[]|select(."hostname-label"=="test1" )'
jq: error: syntax error, unexpected ==, expecting '$' (Windows cmd shell quoting issues?) at <top-level>, line 1: .data[]|select(.hostname-label==test1 ) jq: 1 compile error PS C:\MYDATA\myfiles>
我在 jplay.org 中尝试过同样的方法,它在那里也运行良好。请告诉我如何在 Windows 中解决此问题。
谢谢
【问题讨论】:
-
PowerShell 7.1 的可悲现实是,在传递给 的参数中需要一个 额外的手动 层
\-转义嵌入的"字符外部程序。这可能在 7.2 中得到修复,可能需要选择加入。有关详细信息,请参阅链接副本的 this answer。
标签: powershell jq oracle-cloud-infrastructure