Interview Prep/Linux/Packages, Shell & Text Tools

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
All Linux questions Roadmap: Linux

More on Packages, Shell & Text Tools