Bird
0
0

What is the output of this script?

medium📝 Command Output Q13 of 15
Bash Scripting - Functions
What is the output of this script?
greet() {
  echo "Hello, $1 and $2!"
}
greet Alice Bob
AHello, $1 and $2!
BHello, Alice and Bob!
CHello, Alice and !
DHello, and Bob!
Step-by-Step Solution
Solution:
  1. Step 1: Understand function call and arguments

    The function greet is called with two arguments: Alice and Bob. Inside the function, $1 is Alice and $2 is Bob.
  2. Step 2: Substitute arguments in echo

    The echo command prints: "Hello, Alice and Bob!" exactly as expected.
  3. Final Answer:

    Hello, Alice and Bob! -> Option B
  4. Quick Check:

    Function args $1=Alice, $2=Bob replaced correctly [OK]
Quick Trick: Arguments replace $1, $2 inside function call [OK]
Common Mistakes:
MISTAKES
  • Expecting literal $1 and $2 printed
  • Mixing argument order
  • Forgetting to pass both arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes