Recall & Review
beginner
What does the [[ ]] syntax represent in bash scripting?
It is an extended test command used for conditional expressions, offering more features and safer syntax than the older [ ] test.
Click to reveal answer
intermediate
How does [[ ]] differ from [ ] in bash?
The [[ ]] supports pattern matching with ==, allows && and || inside without escaping, and prevents word splitting and pathname expansion.
Click to reveal answer
beginner
What is the result of this command: [[ "abc" == a* ]] && echo yes || echo no
It prints 'yes' because [[ ]] supports pattern matching, and 'abc' matches the pattern 'a*'.
Click to reveal answer
intermediate
Can you use regex matching inside [[ ]]? If yes, how?
Yes, using the =~ operator, e.g., [[ $var =~ ^[0-9]+$ ]] tests if $var contains only digits.
Click to reveal answer
intermediate
Why is [[ ]] considered safer than [ ] when testing variables?
Because [[ ]] does not perform word splitting or pathname expansion, it avoids errors when variables contain spaces or special characters.
Click to reveal answer
Which of these is a valid use of [[ ]] in bash?
✗ Incorrect
[[ $name == "John" ]] is valid and supports pattern matching. Single brackets require single = for string comparison.
What does this command print? [[ 5 -gt 3 && 2 -lt 4 ]] && echo yes || echo no
✗ Incorrect
Inside [[ ]], you can use && without escaping. Both conditions are true, so it prints 'yes'.
Which operator is used inside [[ ]] for regex matching?
✗ Incorrect
The =~ operator is used for regex matching inside [[ ]].
What happens if a variable with spaces is tested using [ ] without quotes?
✗ Incorrect
Without quotes, [ ] splits words on spaces causing errors. [[ ]] avoids this problem.
Which is true about [[ ]] in bash?
✗ Incorrect
[[ ]] is a shell keyword providing enhanced conditional testing.
Explain the advantages of using [[ ]] over [ ] in bash scripting.
Think about safety and extra features in condition tests.
You got /4 concepts.
Describe how to use regex matching inside [[ ]] and give an example.
Look for the operator that tests patterns, not just equality.
You got /3 concepts.