How to control flow based on booleanish variables in bash scripts

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2023-03-28

Say you have the env variable $SKIP_CI_VERIFICATION. How do you switch on that in your bash script?

There are two basics tests that are relevant: -n and -z

  1. -n tests if "not empty"
if [[ -n $SKIP_CI_VERIFICATION ]]; then
  echo "it is set"
  1. -z tests the opposite (i.e. if empty)
if [[ -z  $SKIP_CI_VERIFICATION ]]; then
  echo "it is NOT set"