Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Functions
What will be the output of this script?
print_args() {
  echo "$2 $1"
}
print_args one two
Aone two
Btwo one
C$2 $1
Done
Step-by-Step Solution
Solution:
  1. Step 1: Identify the arguments passed

    The function is called with one as $1 and two as $2.
  2. Step 2: Analyze the echo statement

    The echo prints $2 first, then $1, so output is "two one".
  3. Final Answer:

    two one -> Option B
  4. Quick Check:

    Order of $2 then $1 reversed [OK]
Quick Trick: Order of $1 and $2 in echo controls output order [OK]
Common Mistakes:
MISTAKES
  • Assuming $1 prints first always
  • Printing variable names literally
  • Ignoring argument order in function call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes