From 3b2d675ed63b1be3ca63ca7caeb76dc55f9ed5e7 Mon Sep 17 00:00:00 2001 From: daryl Date: Thu, 26 May 2022 14:02:40 +0930 Subject: [PATCH] Add 'bash/booleans.bash' --- bash/booleans.bash | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 bash/booleans.bash 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