Bird
0
0

What is wrong with this bash function?

medium📝 Debug Q6 of 15
Bash Scripting - Functions
What is wrong with this bash function?
myfunc() {
  return success
}
myfunc
echo $?
AFunction should use echo instead of return
Breturn expects a numeric argument, not a string
CMissing parentheses in function definition
Decho $? will not print the return value
Step-by-Step Solution
Solution:
  1. Step 1: Understand return argument type

    The return command in bash functions only accepts numeric values (0-255).
  2. Step 2: Identify the error

    Using a string like success as an argument causes an error.
  3. Final Answer:

    return expects a numeric argument, not a string -> Option B
  4. Quick Check:

    Return must be numeric [OK]
Quick Trick: return only accepts numbers, not strings [OK]
Common Mistakes:
MISTAKES
  • Passing strings to return
  • Confusing echo output with return status
  • Assuming return can output text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes