exam questions

Exam LX0-104 All Questions

View all questions & answers for the LX0-104 exam

Exam LX0-104 topic 1 question 11 discussion

Actual exam question from CompTIA's LX0-104
Question #: 11
Topic #: 1
[All LX0-104 Questions]

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
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
linux_admin
2 years, 2 months ago
Result: 3 2 1 Here's what's happening: The echo '1 2 3 4 5 6' command outputs the string 1 2 3 4 5 6 to the standard output. The pipe | symbol is used to redirect the standard output of the echo command as the standard input to the next command in the sequence, which is the while loop. The while loop reads from the standard input, and read is used to read three values at a time from the standard input into the variables a, b, and c. The do keyword starts the body of the while loop, which contains the echo command echo result: $c $b $a. This echo command outputs the values of c, b, and a in reverse order, separated by spaces. The while loop continues to run until there is no more input to read from the standard input. In this case, after three iterations, all of the input has been processed, and the loop terminates. The final result is the output of the last echo command in the loop, which is result: 3 2 1.
upvoted 1 times
linux_admin
2 years, 2 months ago
Disregard, answer A is correct.
upvoted 1 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago