Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
ryo1kato opened this issue May 1, 2016 · 0 comments · Fixed by #1697
Closed

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

ryo1kato opened this issue May 1, 2016 · 0 comments · Fixed by #1697

Comments

@ryo1kato
Copy link
Contributor

ryo1kato commented May 1, 2016

$ 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'.

ryo1kato added a commit to ryo1kato/jq that referenced this issue May 2, 2016
Return the code 1 or 4 based on last output, not last input.
Fixes jqlang#1139
ryo1kato added a commit to ryo1kato/jq that referenced this issue Jul 28, 2018
* Set default error code to -4 in main(), Fixes jqlang#1142
* fix --exit-code with more than one object in input, Fixes jqlang#1139
    - Return code 1 or 4 based on last output, not last input.
ryo1kato added a commit to ryo1kato/jq that referenced this issue Jul 29, 2018
* Set default error code to -4 in main(), Fixes jqlang#1142
* fix --exit-code with more than one object in input, Fixes jqlang#1139
    - Return code 1 or 4 based on last output, not last input.
nicowilliams pushed a commit that referenced this issue Dec 18, 2018
* Set default error code to -4 in main(), Fixes #1142
* fix --exit-code with more than one object in input, Fixes #1139
    - Return code 1 or 4 based on last output, not last input.
rbolsius pushed a commit to rbolsius/jq that referenced this issue Sep 12, 2019
* Set default error code to -4 in main(), Fixes jqlang#1142
* fix --exit-code with more than one object in input, Fixes jqlang#1139
    - Return code 1 or 4 based on last output, not last input.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant