Let's say I execute the following command on a terminal:
this-command-doesnt-exist-and-closes-with-code-127 | jq '' If I execute echo $? I'll get 0 as result because it's checking the exit code from jq. I'd like to know the exit code from the first command on the pipe. I thought about redirecting the stderr like:
this-command-doesnt-exist-and-closes-with-1 2>&1 | jq '' if [ $? != 0 ]; then echo "I got an error" fi Just so I send a message that doesn't make sense to jq. It'd solve the problem but it doesn't look like the right solution for it. How can I manage getting the error code of commands on pipes?