ExamGecko
Home / LPI / 102-500 / Practice Test 1
Ask Question

LPI 102-500 Practice Test 1

00:00:00
Show Answer
Report Issue   Restart test

Question 1 / 40

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

result: 3 4 5 6 2 1
result: 3 4 5 6 2 1
result: 1 2 3 4 5 6
result: 1 2 3 4 5 6
result: 6 5 4
result: 6 5 4
result: 6 5 4 3 2 1
result: 6 5 4 3 2 1
result: 3 2 1
result: 3 2 1
Comment (0)
Suggested answer: E
Explanation:

The while loop reads a line from the standard input and splits it into words using the IFSvariable, which by default contains spaces, tabs, and newlines. The read command assigns thefirst word to the variable a, the second word to the variable b, and the rest of the line to thevariable c. Therefore, in this case, a=1, b=2, and c=3 4 5 6. The echo command prints the valuesof c, b, and a in reverse order, separated by spaces. The output is result: 3 2 1. The loopterminates after reading the first line, since there is no more input to read.Reference:Bashwhile Loop | Linuxize,Bash Scripting - While Loop - GeeksforGeeks

asked 18/09/2024
Miguel Medina Parra
33 questions