Bird
0
0

Which of the following is the correct syntax to start an if statement in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - Conditionals
Which of the following is the correct syntax to start an if statement in bash?
Aif [ condition ]; then
Bif { condition } then
Cif(condition) then
Dif condition then
Step-by-Step Solution
Solution:
  1. Step 1: Recall bash if syntax

    Bash requires spaces around brackets and a semicolon before then: if [ condition ]; then.
  2. Step 2: Check other options

    if(condition) then misses spaces and semicolon, B uses braces incorrectly, D misses brackets and semicolon.
  3. Final Answer:

    if [ condition ]; then -> Option A
  4. Quick Check:

    Spaces and semicolon needed [OK]
Quick Trick: Remember spaces around [ ] and semicolon before then [OK]
Common Mistakes:
MISTAKES
  • No spaces around brackets
  • Missing semicolon before then
  • Using parentheses or braces incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes