为什么在jq中变量没有展开?
为什么这会起作用(变量在Bash中展开)
jq -r "include \"i3\";stack(.id==$ID)|
.[]|select(.type==\"workspace\")|.name" <<< "$TREE"
当这种情况不起作用时(变量在jq中展开)
jq -r --arg ID "$ID" 'include "i3";stack(.id==$ID)|
.[]|select(.type=="workspace")|.name' <<< "$TREE"
i3.jq的调用栈(感谢)
def stack(condition):
if condition then
[.], [.] + ((.nodes + .floating_nodes)[]
| stack(condition))
elif . then
[.] + ((.nodes + .floating_nodes)[]
| stack(condition))
else
empty
end;
解决方案
--arg 将该值作为字符串传递。若JSON .id 是一个数字,请改用 --argjson。
jq --argjson ID "$ID" 'stack(.id == $ID)'
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。