QuestionQ14

Shells y scripts

What output does the following command sequence produce?

echo '1 2 3 4 5 6' | while read a b c; do  
echo result $c $b $a;  
done  
  • A result: 6 5 4
  • B result: 1 2 3 4 5 6
  • C result: 3 4 5 6 2 1
  • D result: 6 5 4 3 2 1
  • E result: 3 2 1
Explanation

When read receives more fields than there are variables, it assigns the remaining input fields to the final variable. Therefore, a receives 1, b receives 2, and c receives 3 4 5 6; expanding $c $b $a prints result 3 4 5 6 2 1.

Community Discussion

No comments yet. Be the first to start the discussion!