Bird
0
0

What is the output of this script if the user inputs: red blue green yellow?

medium📝 Command Output Q4 of 15
Bash Scripting - User Input
What is the output of this script if the user inputs: red blue green yellow?
read a b c
echo "$a"
echo "$b"
echo "$c"
Ared blue green
Bred blue green yellow
Cred blue green yellow
Dred blue yellow green
Step-by-Step Solution
Solution:
  1. Step 1: Understand how read assigns input

    With three variables and four words, the last variable gets all remaining words.
  2. Step 2: Assign input to variables

    a='red', b='blue', c='green yellow'.
  3. Final Answer:

    red blue green yellow -> Option C
  4. Quick Check:

    Last variable gets all leftover input [OK]
Quick Trick: Last variable gets all leftover input words [OK]
Common Mistakes:
MISTAKES
  • Assuming each variable gets one word only
  • Expecting error on extra input
  • Splitting leftover input incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes