Conditional execution in Bash revolves around if, elif, else, and fi. The condition itself is a list of commands whose exit status determines the branch: zero is true and non-zero is false. The three most common test constructs are [ ], [[ ]], and (( )). The single-bracket [ ... ] is the POSIX test builtin: it is portable but performs word splitting on its operands, so variables inside it must be quoted. The double-bracket [[ ... ]] is a Bash keyword that does not word-split its operands and adds Bash-specific features, most notably == glob matching and =~ regular-expression matching. The arithmetic form (( ... )) evaluates an integer expression and returns 0 (true) when the result is non-zero.
File-test operators inside [[ ]] include -e (exists), -f (regular file), -d (directory), -L (symlink), -r, -w, -x (readable, writable, executable), and -s (size greater than zero); they are negated with !. String tests include -z (empty), -n (non-empty), == and != (with the right-hand side optionally a glob), and < and > for lexicographic comparison. For integer comparison, prefer (( a == b )) or the [[ ]] operators -eq, -ne, -lt, -le, -gt, and -ge; do not use the lexicographic < and > operators on integers. A classic pitfall illustrates why quoting matters: if [ \(foo = "bar" ] fails with a syntax error when foo is empty, because word splitting expands it to [ = "bar" ]. The fix is to quote the variable, as in if [ "\)foo" = "bar" ], or to use [[ "$foo" == "bar" ]], which avoids the issue altogether.
Pattern-based multi-way branching uses a case statement, whose right-hand side supports glob patterns and | alternations and which ends with esac. Regex matching lives in [[ ]] as well: [[ "\(s" =~ ^[0-9]+\) ]] tests for an all-digits string, and capture groups after a successful match are available through the \({BASH_REMATCH[1]}, \){BASH_REMATCH[2]}, ... array. To detect which operating system the script is running on, [[ "$(uname)" == "Linux" ]] (or a case over uname -s) gates platform-specific code, and [[ $EUID -eq 0 ]] checks whether the script is running as root.