Bird
0
0

Identify the error in this script:

medium📝 Debug Q14 of 15
Bash Scripting - Functions
Identify the error in this script:
greet() {
  echo "Hi $name"
}
greet John
AFunction greet is not defined correctly
BMissing semicolon after echo
CFunction call syntax is wrong
DVariable $name is not set or passed
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage inside function

    The function uses $name, but no variable named name is set or passed.
  2. Step 2: Check function call and argument passing

    The function is called with "John" as argument, but the function does not use $1 to access it.
  3. Final Answer:

    Variable $name is not set or passed -> Option D
  4. Quick Check:

    Use $1 to access arguments, not undefined variables [OK]
Quick Trick: Use $1 inside function to get passed arguments [OK]
Common Mistakes:
MISTAKES
  • Using undefined variables instead of $1
  • Assuming arguments auto-assign to variable names
  • Ignoring function call syntax correctness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes