简体   繁体   中英

JQ argument error in bash script

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM