Bird
0
0

What happens if a recursive Bash function does not have a base case?

easy🧠 Conceptual Q1 of 15
Bash Scripting - Functions
What happens if a recursive Bash function does not have a base case?
AThe function will run only once and then stop
BThe function will convert into a loop automatically
CThe function will return an error immediately
DThe function will call itself indefinitely, causing a stack overflow
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of a base case in recursion

    A base case stops the recursion by providing a condition to end the repeated calls.
  2. Step 2: Analyze what happens without a base case

    Without a base case, the function keeps calling itself endlessly, using more memory each time until the system runs out of stack space.
  3. Final Answer:

    The function will call itself indefinitely, causing a stack overflow -> Option D
  4. Quick Check:

    Base case missing = infinite recursion [OK]
Quick Trick: Always include a base case to stop recursion [OK]
Common Mistakes:
MISTAKES
  • Assuming recursion stops automatically
  • Confusing base case with recursive step
  • Thinking recursion converts to loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes