What output will the following command sequence produce?

Topic 1, Shells, Scripting and Data Management

What output will 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: 3 4 5 6 2 1
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

Answer: E

Explanation:

The while loop reads a line from the standard input and splits it into words using the IFS variable, which by default contains spaces, tabs, and newlines. The read command assigns the first word to the variable a, the second word to the variable b, and the rest of the line to the variable c. Therefore, in this case, a=1, b=2, and c=3 4 5 6. The echo command prints the values of c, b, and a in reverse order, separated by spaces. The output is result: 3 2 1. The loop terminates after reading the first line, since there is no more input to read.

Reference: Bash while Loop | Linuxize, Bash Scripting – While Loop – GeeksforGeeks

Latest 102-500 Dumps Valid Version with 194 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments