Bird
0
0

Consider this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - Functions
Consider this script snippet:
source lib.sh
greet "Bob"

But running it gives: main.sh: line 2: greet: command not found
What is the most likely cause?
Alib.sh does not define the greet function
BThe source command is misspelled
CThe greet function is called before sourcing lib.sh
Dlib.sh has wrong file permissions
Step-by-Step Solution
Solution:
  1. Step 1: Check function definition in lib.sh

    If greet is not defined in lib.sh, sourcing won't load it.
  2. Step 2: Analyze error message

    "command not found" means the function is missing, not a syntax or permission error.
  3. Final Answer:

    lib.sh does not define the greet function -> Option A
  4. Quick Check:

    Missing function definition = lib.sh does not define the greet function [OK]
Quick Trick: Check if function exists in sourced file first [OK]
Common Mistakes:
MISTAKES
  • Assuming source command typo without checking
  • Ignoring function order in script
  • Not verifying file permissions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes