Note that [[ is actually a command/program that returns either 0 (true) or 1 (false). Any program that obeys the same logic (like all base utils, such as grep(1) or ping(1)) can be used as condition.
# and / or
[[ cond1 && cond2 ]]
[[ cond1 || cond2 ]]Files
# Exists
[[ -e FILE ]]
# Readable
[[ -r FILE ]]
# Symlink
[[ -h FILE ]]
# Directory
[[ -d FILE ]]
# Writable
[[ -w FILE ]]
# Size is > 0 bytes
[[ -s FILE ]]
# Is file
[[ -f FILE ]]
# Executable
[[ -x FILE ]]String Conditionals
# String is empty
VAR=''
if [[ -z $VAR ]]; then
echo "String is empty."
fi
# is string not empty
[[ -n $STRING_VAR ]]
# is string equal / not equal
[[ $STRING_VAR == "test" ]]
[[ $STRING_VAR != "test" ]]
# Strings are equal
VAR1="Linuxize"
VAR2="Linuxize"
if [ "$VAR1" = "$VAR2" ]; then
echo "Strings are equal."
else
echo "Strings are not equal."
fi
# Substring in String
VAR='GNU/Linux is an operating system'
if [[ $VAR == *"Linux"* ]]; then
echo "It's there."
fiNumbers
# compare numbers (-eq, -ne, -lt (less), -le (less or equal), -gt (greater), -ge)
[[ $NUM_VAR1 -eq $NUM_VAR2 ]]
# numeric conditions
(( NUM < NUM ))