How do you write conditional statements in bash?

Answer

Bash uses if/elif/else/fi for conditionals. Syntax: if [ condition ]; then ... elif [ condition ]; then ... else ... fi. Common test operators: -eq/-ne/-lt/-gt (numeric), ==/!= (string), -z (string empty), -n (string not empty), -f (file exists), -d (directory exists), -r/-w/-x (readable/writable/executable). The [[ ]] construct (bash-specific) is preferred: supports &&/|| directly, pattern matching with =~, and avoids word-splitting issues. Short-circuit: command && echo ok runs second only if first succeeds; command || echo fail runs second only if first fails.