#!/bin/bash
#
# More about conditional statements:
#
# 1. The [[ .. ]] test
# This is a Bash/KornShel extensions and is not POSIX.
# It's more powerful, safer, and usually preferred in Bash scripts.
# But it may not work with /bin/sh
# Operators include:
#     == and != for string comparison, with pattern matching
#     Example: [[ $s == foo* ]]
#
#     =~ for regex matching
#
#     Plus, no pathname expansion or word splitting inside, so quoting is
#     less fragile

x=foobar
if [[ $x == foo* ]]; then
    echo "x starts with 'foo'"
fi

# Another example:
y=1039472
if [[ $y =~ ^[0-9]+$ ]]; then
    echo "y is all digits"
fi

# 2. The test command
# If is virtually equivalent to '['.
# In fact, in some systems '[' is an link to 'test'
x=foo
test "$x" = foo && echo "x is foo"

# Another example:
test "$(whoami)" != 'root' && echo "you are using a non-privileged account"

# You can also use ||
test "$EUID" = 0 || echo "this script needs to be run by root"

