JQ argument error in bash script

荒凉一梦 提交于 2020-01-30 12:28:06

问题


I have a problem with a JQ query:

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

Any solution?


回答1:


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))"

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))'


来源:https://stackoverflow.com/questions/40514605/jq-argument-error-in-bash-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!