Bird
0
0

What will be the output of this bash script?

medium📝 Command Output Q13 of 15
Bash Scripting - Functions
What will be the output of this bash script?
say_hello() {
  echo "Hello, $1!"
}
say_hello Alice
AError: function not found
BHello, Alice!
Csay_hello Alice
DHello, $1!
Step-by-Step Solution
Solution:
  1. Step 1: Understand function call with argument

    The function say_hello takes one argument and prints it using $1.
  2. Step 2: Substitute argument and print

    Calling say_hello Alice replaces $1 with "Alice", so output is "Hello, Alice!".
  3. Final Answer:

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

    Function argument $1 = Alice [OK]
Quick Trick: Use $1 to access first argument inside bash functions [OK]
Common Mistakes:
MISTAKES
  • Printing literal $1 instead of its value
  • Forgetting to call the function
  • Syntax errors in function definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes