Skip to main content
InterviewHubPRO
Section Overview
Q6

Question 6 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

12%
Bash & Shell Scripting (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is the difference between `[[ ... ]]` and `[ ... ]` (test command)?

junior Levelbash-shellBasic

In Simple Words:

  • [ ... ] (POSIX standard / test): Classic shell command. Prone to syntax errors if variables are empty or contain spaces ([ $foo = "bar" ] crashes if $foo is empty!).
  • [[ ... ]] (Bash Keyword - Best Practice): Built into Bash:
    • Does not undergo word splitting or glob expansion.
    • Supports regular expression matching via the =~ operator: [[ "$email" =~ ^[A-Z0-9._%+-]+@ ]].
    • Supports logical operators && and || directly inside brackets: [[ $a -gt 5 && $b -lt 10 ]].