Linux Administration
medium

Questão de Linux Administration #019e3987

Enunciado da Questão
Linux Administration
#read
#while-loop
#variable-splitting
#word-splitting
#echo
Médio

What output will the following command sequence produce?

echo '1 2 3 4 5 6' | while read a b c; do

echo result: b $a;

done

A

result: 3 4 5 6 2 1

Correta
B

result: 1 2 3 4 5 6

C

result: 6 5 4

D

result: 6 5 4 3 2 1

E

result: 3 2 1

Explicação Oficial / Explicações da Comunidade

The command sequence uses a while loop with read to process a string of numbers. The read command reads input into variables, splitting by whitespace. By default, read assigns the first word to the first variable, the second word to the second variable, and the remaining words to the last variable. Here, a, b, and c are specified. The input string is '1 2 3 4 5 6'. The first word 1 goes to a, the second word 2 goes to b, and the rest 3 4 5 6 go to c. The echo statement prints result: $c $b $a, which becomes result: 3 4 5 6 2 1. This is the only iteration because the input is a single line. The output is result: 3 4 5 6 2 1.