Bird
0
0

What is the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Functions
What is the output of this script?
greet() {
  echo "Hi, $1!"
}
greet Bob
AError: function not found
Bgreet Bob
CHi, $1!
DHi, Bob!
Step-by-Step Solution
Solution:
  1. Step 1: Understand function definition and call

    The function greet prints "Hi, $1!", where $1 is the first argument passed.
  2. Step 2: Substitute argument and output

    Calling greet Bob replaces $1 with "Bob", so output is "Hi, Bob!".
  3. Final Answer:

    Hi, Bob! -> Option D
  4. Quick Check:

    Function argument substitution = output with argument [OK]
Quick Trick: Use $1 for first argument inside function [OK]
Common Mistakes:
MISTAKES
  • Printing literal $1
  • Expecting function name as output
  • Syntax errors in function call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes