What's the difference between `[ ]`, `[[ ]]`, and `(( ))`?
⚡
Quick Answer
[ ] is the POSIX test command, [[ ]] is bash's safer conditional (no word-splitting, regex/&&), (( )) is arithmetic evaluation.
Detailed Answer
[[ ]] avoids the quoting pitfalls of [ ], supports == pattern matching, =~ regex, and && / ||. (( )) evaluates integer math and returns success on non-zero. Prefer [[ ]] in bash scripts; use [ ] only for POSIX-sh portability.
Code Example
if [[ $count -gt 0 && $name == prod-* ]]; then ...; fi
💡
Interview Tip
Recommend [[ ]] in bash for safety.
bashconditionalstest