For now I'm using this in my script:
set -euxo pipefail
This will make my bash script fail immediatly if there is an error in my pipe. When I leave this option my script will run fully and end with exit 0 (no error).
I want to have a mix of both. I want to end the whole script but have exit 1; at the end if there was an error in a pipe.
My script looks like this:
#!/bin/bash
set -euxo pipefail
curl --fail --compressed -u "$CREDS" -X GET --header 'Accept: xxx' --header 'Accept-Language: de-DE' 'https://api/call1' | jq -S "." > "output1.json"
curl --fail --compressed -u "$CREDS" -X GET --header 'Accept: xxx' --header 'Accept-Language: de-DE' 'https://api/call2' | jq -S "." > "output2.json"
cat output1.json
cat output2.json
So I don't want to exit the script if call1 fails. If call1 fails I want to go to call2 and the cat commands before exiting the script with exit code 1.