Bird
0
0

Identify the error in this bash function:

medium📝 Debug Q14 of 15
Bash Scripting - Functions
Identify the error in this bash function:
myfunc() {
  return "Success"
}
myfunc
echo $?
Areturn expects a number, not a string
Becho cannot print return values
CFunction missing parentheses
Dreturn must be last command in function
Step-by-Step Solution
Solution:
  1. Step 1: Understand return command rules

    In bash, return must be followed by a numeric status (0-255), not a string.
  2. Step 2: Identify the error in the code

    The code tries to return "Success" (a string), which causes an error.
  3. Final Answer:

    return expects a number, not a string -> Option A
  4. Quick Check:

    return only accepts numbers [OK]
Quick Trick: return only accepts numbers, not text [OK]
Common Mistakes:
MISTAKES
  • Trying to return strings with return
  • Confusing echo and return usage
  • Assuming return prints output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes