Bird
0
0

Find the problem in this script:

medium📝 Debug Q7 of 15
Bash Scripting - Functions
Find the problem in this script:
myfunc() {
  echo "$1 and $3"
}
myfunc apple banana
A$3 is not passed, so it is empty
BFunction name is invalid
CMissing quotes around arguments
DCannot use $3 inside functions
Step-by-Step Solution
Solution:
  1. Step 1: Check arguments passed to function

    The function is called with two arguments: apple and banana. So $1 = apple, $2 = banana, but $3 is not passed.
  2. Step 2: Understand effect of missing $3

    Since $3 is not provided, it is empty, so echo prints "apple and " with nothing after.
  3. Final Answer:

    $3 is not passed, so it is empty -> Option A
  4. Quick Check:

    Missing argument $3 results in empty value [OK]
Quick Trick: Only passed arguments have values; missing ones are empty [OK]
Common Mistakes:
MISTAKES
  • Assuming $3 has a default value
  • Thinking function name is wrong
  • Ignoring missing arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes