status_verification
verify_pipe_status() {
local pipe_status=("${PIPESTATUS[@]}")
local idx=0
# Iterate through each status in PIPESTATUS
for status in "${pipe_status[@]}"; do
# Check if the status is non-zero
if [ "$status" -ne 0 ]; then
# Provide a detailed error message with the index of the failed command
interrupt "Error: Command at pipeline index $idx failed with exit code $status."
fi
# Increment the index for the next iteration
((idx++))
done
}
foo_unhappy(){
echo "foo_unhappy"
return 1
}
foo_happy(){
echo "foo_happy"
return 0
}
main() {
foo_happy | foo_unhappy | grep "foo" | tee /tmp/out
verify_pipe_status
echo "MAIN FINISHED"
}
main "${@}" || exit 1
Backlinks