Quantcast
Channel: How can I get this script to error exit based on result of for loop? - Unix & Linux Stack Exchange
Browsing all 7 articles
Browse latest View live

Answer by DevOps-Eng for How can I get this script to error exit based on...

You can simply add the --fail option to the curl command, this will solve your problem, the script will fail and exit on error if the curl command fails, if very useful too when using curl in jenkins...

View Article



Answer by G32RW for How can I get this script to error exit based on result...

If errexit is set and the curl command fails the script terminates right after the failed curl command. In the bash manual there is no hint that set -e ignores any failed return status of a single in a...

View Article

Answer by rexkogitans for How can I get this script to error exit based on...

set -o errexit can be tricky in loops and subshells, because you have to pass the way back out of the process. Breaking a loop (even in normal operation) is considered bad practice. You can call me...

View Article

Answer by RobertL for How can I get this script to error exit based on result...

If you have errexit set, then the false statement should cause the script to exit immediately. Same thing if the curl command failed. You're example script, as written, should exit after the first curl...

View Article

Answer by John1024 for How can I get this script to error exit based on...

Replace: done with: done || exit 1 This will cause the code to exit if the for loop exits with a non-zero exit code. As a point of trivia, the 1 in exit 1 is not needed. A plain exit command would exit...

View Article


How can I get this script to error exit based on result of for loop?

I have a bash script which uses set -o errexit so that on error the entire script exits at the point of failure. The script runs a curl command which sometimes fails to retrieve the intended file -...

View Article

Answer by Max Bileschi for How can I get this script to error exit based on...

If you prefer to stop the loop on the first failure, and also to avoid set -e, you can do something like this:for i in `seq 1 10`; do run_command || exit 1;done

View Article
Browsing all 7 articles
Browse latest View live




Latest Images