diff --git a/bash/booleans.bash b/bash/booleans.bash new file mode 100644 index 0000000..91fa201 --- /dev/null +++ b/bash/booleans.bash @@ -0,0 +1,23 @@ +#!/bin/bash + +# BASH doesn't actually understand booleans. +# What you can do however is to trick it by using the fact that the true and false commands return 0 and 1, +# so it can stand in for boolean algebra if used correctly. + +BOOLEAN1=false + +if $BOOLEAN1; then + echo "We won't get here because BOOLEAN1 is false." +fi +if ! $BOOLEAN1; then + echo "But we DO get here." +fi + +BOOLEAN1=true + +if $BOOLEAN1; then + echo "Now we do get in this as it's been set to true." +fi +if ! $BOOLEAN1; then + echo "And now we DON'T get here." +fi