Bird
0
0

Why does the last variable in a read command receive all remaining input words if there are more words than variables?

hard🧠 Conceptual Q10 of 15
Bash Scripting - User Input
Why does the last variable in a read command receive all remaining input words if there are more words than variables?
ABecause read concatenates leftover input into the last variable
BBecause read throws an error and stops reading
CBecause read ignores extra input words
DBecause read assigns only the first word to each variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand read input assignment

    read splits input by spaces and assigns one word per variable in order.
  2. Step 2: Handle extra input words

    If input words exceed variables, read assigns all leftover words concatenated with spaces to the last variable.
  3. Final Answer:

    Because read concatenates leftover input into the last variable -> Option A
  4. Quick Check:

    Leftover input goes to last variable concatenated [OK]
Quick Trick: Last variable gets all leftover input concatenated [OK]
Common Mistakes:
MISTAKES
  • Thinking read throws error on extra input
  • Assuming extra input is ignored
  • Believing each variable gets only one word always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes