Boolean Best Practices

It is best to use booleans in your scripts rather than using an integer to check for the truth of a statement. The reason for this is that it cleans up the code and makes it more intuitive when mapping values to parameter.

For example, if a parameter is called Create Full Backup, true makes more sense than 1

Bash

true and false are native to Mac and Linux operating systems, this means variable can be evaluated without assigning integers.

For example:

1if {attuneVar}
2then
3    echo "true"
4fi

Attune substitutes the a value into the {attuneVar} parameter.

If the value is true :

1if true
2then
3    echo "true"
4fi
../_images/bash_bool.png

If you want to evaluate a variable as false, you can use the NOT operator !

1if ! false
2then
3    echo 'This is false'
4fi

Multiple values can be evaluated with the AND operator &&

1if true && ! false
2then
3    echo 'The first value is true and the second value is false'
4fi

Powershell

The same is true for Powershell except Powershell use $true and $false.

For example:

1if (${{attuneVal}}) {
2    Write-Host "true"
3}

Attune substitutes the value into the {attuneVar} parameter.

If the value is true :

1if ($true) {
2    Write-Host "true"
3}
../_images/powershell_bool.png

If you want to evaluate a variable as false, you can use the NOT operator -not

1if -not ($false) {
2    Write-Host "Not False"
3}

Python

Python uses True and False. To keep the use of booleans consistent throughout a project, you are able to assign the booleans to variables at the beginning of a Python script.

For example:

1true=True
2false=False
3
4if {attuneVal}:
5    print("Do the work for true")
6else
7    print("Do the work for else")

If the Parameter is mapped to true, Attune substitutes true into the {attuneVal} parameter which is assigned to True.

1true=True
2false=False
3
4if true:
5    print("Do the work for true")
6else
7    print("Do the work for else")
../_images/python_bool.png

If you want to evaluate a variable as false, you can use the NOT operator not

1true=True
2false=False
3
4if not false:
5    print("Do the work for true")
6else
7    print("Do the work for else")

Multiple values can be evaluated with the AND operator and

1true=True
2false=False
3
4if not false and true:
5    print("Do the work for true")
6else
7    print("Do the work for else")