[英]JQ argument error in bash script
I have a problem with a JQ query: 我有一个JQ查询问题:
max=$(script) <-- (return integer)
jq -r ".notifiestext | map(select(.read==false))" temp_notif |
jq --arg foo "$max" "map(select(.id<$foo))"
I get the following error: 我收到以下错误:
jq: error: syntax error, unexpected ')' (Unix shell quoting issues?) at <top-level>, line 1: map(select(.id<))
The ".id" parameter is an integer “ .id”参数是整数
Any solution? 有什么办法吗?
You need to escape the $
for $foo
so that the shell doesn't try to expand it as a parameter before jq
even runs. 您需要对$foo
的$
进行转义,以便外壳程序甚至在jq
运行之前都不会尝试将其扩展为参数。
jq -r ".notifiestext | map(select(.read==false))" temp_notif |
jq --arg foo "$max" "map(select(.id<\$foo))"
It would be better to use single quotes for the jq
filter instead. 最好对jq
过滤器使用单引号。
jq -r '.notifiestext | map(select(.read==false))' temp_notif |
jq --arg foo "$max" 'map(select(.id<$foo))'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.