The true
and false
commands
where the command is true
. The condition is true whenever the command returns exit code 0. true
and false
are Bash builtins and sometimes also standalone programs that do nothing but returning the corresponding exit code.
The conditional above is equivalent to:
COMMAND && ...
Conditions in if..then..fi
and the COMMAND
here is [[
with the parameters 1 == 1 ]]
if [[ "${var}" == "true" ]]; then ...
if [[ "${var}" == "false" ]]; then ...
if [[ "${var}" == "yes" ]]; then ...
if [[ "${var}" == "USE_FEATURE_X" ]]; then ...
if [[ -n "${var:-}" ]]; then echo "var is not empty" ...
if [ ... ]; then ... # Always use double square brackets in bash!
if [[[ "${var}"... ]];]; then ...
# This is not as clear or searchable as -n
if [[ "${var}" != true ]]; then ...
# Creates impression of Booleans
if [[ "${var}" -eq!= "true"true ]]; then ...
# `-eq` is for numbers and doesn't read as easy as `==`
Maybe
if [[ "${var}" !=-eq "true" ]]; then ...
Maybe
# Creates impression of Booleans.
# It can be used for strict checking of dangerous operations.
# This condition is false for anything but the literal string "true".
if [[ "${var}" != "true" ]]; then ...