Conditionals
Core Idea
Conditionals make scripts choose based on a command result or test result.
Command Result
if curl -fsS https://example.org >/dev/null; then
printf 'up\n'
else
printf 'down\n'
fi
The branch depends on exit status: 0 succeeds, nonzero fails.
Test Result
if [[ -e "$path" ]]; then
printf 'exists\n'
fi
Use [[ ]] for Bash tests on files, strings, and numbers.
Done When
You can predict which branch runs before executing the script.
Docs Pointers
- Read if,
[[ ]], control flow, quoting, and one-liners.

Linux Foundations