What is the difference between [ ] and [[ ]] in bash?

Answer

[ ] is the POSIX-standard test command (also /usr/bin/[). It has strict quoting requirements — unquoted variables with spaces cause word splitting and errors. [[ ]] is a bash keyword (not a command) with enhanced features: supports && and || directly, regex matching with =~, pattern matching with ==, no word splitting on unquoted variables, and more natural behavior overall. Example: [[ "$str" =~ ^[0-9]+$ ]] tests if string is all digits. Best practice: use [[ ]] in bash scripts for safety and power; use [ ] only when writing POSIX sh-compatible scripts. Arithmetic comparisons: use (( )) — e.g., ((x > 5)).