I'm trying to capture the stderr of a subcommand, my idea is something like this:
subErr(){
echo "${1}"
exit 1
}
BLOB=$(some long command || subErr $2)
aws configure set x_security_token_expires $(echo $BLOB|jq -r '.Credentials.Expiration') --profile DEFAULT
So basically if the command fails, feed the stderr to a function which prints the error and exits.
If the command succeeds assign stdout to BLOB and continue processing
How can I achieve this?