Skip to content

jq -e returns 4 for non-empty output with select() #1139

@ryo1kato

Description

@ryo1kato
$ cat test.json
{"key": 1}
{"key": 2}
{"key": 3}

$ for i in 1 2 3 4
do
     echo "==== i=$i ===="
     jq --exit-status -c "select(.key == $i)" test.json
     echo ret=$?
done
==== i=1 ====
{"key":1}
ret=4
==== i=2 ====
{"key":2}
ret=4
==== i=3 ====
{"key":3}
ret=0
==== i=4 ====
ret=4

The man page says "Sets the exit status of jq to [...] 4 if no valid result was ever produced", but it seems the command returns 4 whenever last object is filtered out. (it should return '4' only for i=4 case above)

$ jq --exit-status -c 'select(.key == 1) | (.key!=1) ' test.json; echo ret=$?
false
ret=4

Similarly, I think this should return '1' instead of 4, because it's last output (which is not last one in the input, though) is 'false'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions