Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Using select with -e: exit code only depends on last item #2500

Closed
pswaminathan opened this issue Nov 15, 2022 · 3 comments
Closed

Using select with -e: exit code only depends on last item #2500

pswaminathan opened this issue Nov 15, 2022 · 3 comments

Comments

@pswaminathan
Copy link

Describe the bug
Using select, the exit code when using the -e flag depends only on the last item processed, not any item.

To Reproduce

$ echo '{"some": "out", "success": true}\n{"some": "out", "success": false}' | jq -e 'select(.success)' 1>/dev/null; echo $?
4

$ echo '{"some": "out", "success": false}\n{"some": "out", "success": true}' | jq -e 'select(.success)' 1>/dev/null; echo $?
0

Expected behavior
Both of the above lines produce the same output (when run without the output flags):

$ echo '{"some": "out", "success": true}\n{"some": "out", "success": false}' | jq -e 'select(.success)'
{
  "some": "out",
  "success": true
}

I would expect the exit code to be 0 for both, as valid output was produced. Instead, the exit codes differ depending on whether or not the last item produced a valid output.

Environment (please complete the following information):

  • OS and Version: macOS Monterey 12.6.1
  • jq version 1.6

Additional context
N/A

@wader
Copy link
Member

wader commented Nov 15, 2022

Hi, could you try jq master? brew install --HEAD jq if your using homebrew. I suspect this might be fixed by #1697 that was merged after jq 1.6

@pswaminathan
Copy link
Author

Yes, that fixed it! I tried to look for open issues first. Seems I didn't search effectively enough, as I didn't see the issue that fixed. Thanks for your help!

@wader
Copy link
Member

wader commented Nov 15, 2022

@pswaminathan 👍 no problem, hope there will be new release eventually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants