Bird
0
0

What will the following bash function print when called as show_args apple banana?

easy🧠 Conceptual Q2 of 15
Bash Scripting - Functions
What will the following bash function print when called as show_args apple banana?
show_args() {
  echo "$1 and $2 are fruits"
}
Aand are fruits
Bbanana and apple are fruits
C$1 and $2 are fruits
Dapple and banana are fruits
Step-by-Step Solution
Solution:
  1. Step 1: Identify the arguments passed to the function

    The function is called with two arguments: apple and banana. So, $1 = apple, $2 = banana.
  2. Step 2: Understand the echo statement

    The echo prints the values of $1 and $2 followed by the text "are fruits".
  3. Final Answer:

    apple and banana are fruits -> Option D
  4. Quick Check:

    Arguments $1 and $2 print in order [OK]
Quick Trick: Arguments print in order: $1 first, $2 second [OK]
Common Mistakes:
MISTAKES
  • Swapping $1 and $2 values
  • Printing variable names instead of values
  • Ignoring the order of arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes