Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Supress bash script exiting

I’m trying to use conditional logic for Helm package manager, ie. if the release is installed then helm should not install the same release, if not installed then helm should install it. So very basic conditional logic. My question though is not about Helm but rather bash scripting.

To check if Helm release is installed I’m using:

RELEASE_INSTALLED=$(helm status RELEASE_NAME -o json | jq -r ".info.status")

When it is installed then I’m getting string value deployed defined in RELEASE_INSTALLED variable. But when it is not then my bash script exits with error code 1. I would like my script to continue executing instead of immediately exiting. Then I could build some conditional logic if basically the command above fails. How can I do that having these settings at the beginning of the script?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

set -o errexit
set -o pipefail

>Solution :

You can use a conditional expression.

RELEASE_INSTALLED=$(helm status RELEASE_NAME -o json | jq -r ".info.status" || echo 'not deployed')

errexit and pipefail don’t apply if the failing command is part of a conditional expression.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading