What is the difference between `[ ]` and `[[ ]]` in bash?
IntermediateConceptPackages, Shell & Text Tools
Answer
[ is the POSIX test command, so unquoted empty variables cause syntax errors and < is treated as redirection. [[ ]] is a bash keyword: no word splitting, supports &&/|| inside, pattern matching ==, and regex =~.
if [[ -f "$cfg" && $env == prod* ]]; then echo ok; fi
if [[ $ip =~ ^10\. ]]; then echo private; fi
More on Packages, Shell & Text Tools
Compare apt and dnf package management.BeginnerWhat is the difference between `apt upgrade` and `apt full-upgrade`?IntermediateHow do you find which package provides a file or command?BeginnerHow do you pin or hold a package version?IntermediateHow are repositories and their GPG keys configured?AdvancedWhat is the difference between a login shell and an interactive non-login shell?Intermediate