bash脚本中的JQ参数错误 [英] JQ argument error in bash script
本文介绍了bash脚本中的JQ参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对JQ查询有疑问:
max=$(script) <-- (return integer)
jq -r ".notifiestext | map(select(.read==false))" temp_notif |
jq --arg foo "$max" "map(select(.id<$foo))"
我收到以下错误:
jq: error: syntax error, unexpected ')' (Unix shell quoting issues?) at <top-level>, line 1: map(select(.id<))
.id"参数是整数
有解决方案吗?
推荐答案
您需要将$foo
的$
转义,以便外壳程序甚至在jq
运行之前都不会尝试将其扩展为参数.
You need to escape the $
for $foo
so that the shell doesn't try to expand it as a parameter before jq
even runs.
jq -r ".notifiestext | map(select(.read==false))" temp_notif |
jq --arg foo "$max" "map(select(.id<\$foo))"
最好在jq
过滤器中使用单引号.
It would be better to use single quotes for the jq
filter instead.
jq -r '.notifiestext | map(select(.read==false))' temp_notif |
jq --arg foo "$max" 'map(select(.id<$foo))'
这篇关于bash脚本中的JQ参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文