Bird
0
0

What will be the output of this bash script?

medium📝 Command Output Q4 of 15
Bash Scripting - Functions
What will be the output of this bash script?
greet() {
  echo "Welcome, $1!"
}
greet User
AWelcome, User!
Bgreet User
CWelcome, $1!
DError: function not defined
Step-by-Step Solution
Solution:
  1. Step 1: Understand function call and parameter usage

    The function greet takes the first argument $1 and echoes a welcome message.
  2. Step 2: Analyze the call

    The function is called with argument User, so $1 is replaced by User.
  3. Final Answer:

    Welcome, User! -> Option A
  4. Quick Check:

    Function parameters are replaced by passed arguments [OK]
Quick Trick: Function arguments replace $1, $2, etc. [OK]
Common Mistakes:
MISTAKES
  • Confusing literal $1 with argument substitution
  • Expecting function name to print
  • Assuming error without syntax issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes