How to force jq returns a valid exit code to shell?
Observe this result:
jq -c '.timesheet.monday' jsons/2021-07.json && echo 'Yes, we have an entry on Monday!'
This is ok … but the following ouput is not what we expect to see:
jq -c '.timesheet.saturday' jsons/2021-07.json && echo 'Yes, we have an entry on Saturday!'
So, we can force jq
exits with an error code in case we have a null
result:
jq -ce '.timesheet.saturday' jsons/2021-07.json || echo 'Ok, we do not have an entry on Saturday!'
|