exam questions

Exam 102-500 All Questions

View all questions & answers for the 102-500 exam

Exam 102-500 topic 1 question 43 discussion

Actual exam question from LPI's 102-500
Question #: 43
Topic #: 1
[All 102-500 Questions]

What output is produced by the following command sequence?
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
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
mustache
Highly Voted 3 years, 11 months ago
Answer C: a is assigned the value 1, b is assigned the value 2, and c gets the rest of the line "3 4 5 6". You print out c (3 4 5 6), then b (2), then a (1), giving you output you see
upvoted 38 times
blk_542
1 year, 1 month ago
Your explanation is odd, but I tested it and it is true: echo '1 2 3 4 5 6' | while read a b c d e f; do echo result $c $b $a; done result 3 2 1 since it proves that a=1, b=2 and c=3 (which in the original question above would correspond to the remainning 3 4 5 6, read also respected the spacing!)
upvoted 1 times
...
[Removed]
1 year, 1 month ago
Tricky
upvoted 1 times
...
thanux
1 year, 12 months ago
Thanks for the explanation :)
upvoted 1 times
...
iwkno6
2 years, 10 months ago
Thanks for the explanation :)
upvoted 2 times
...
...
brrbrr
Highly Voted 3 years, 11 months ago
$ 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
upvoted 6 times
...
fjcsanchez
Most Recent 4 months, 2 weeks ago
C is correct
upvoted 1 times
...
M_ukesh8
7 months, 2 weeks ago
Tricky one
upvoted 1 times
...
klever
1 year, 6 months ago
You can just grab this code and put it into the script, use chmod u+x and execute and see what it does. The output is "result 3 4 5 6 2 1"
upvoted 1 times
...
bestiutza
1 year, 8 months ago
because c is the last value the rest of the numbers are assigned to it: 123456 abc So a is 1, b is 2, c is 3456. If we had 123456 abcd..the output would have been a for 1 b for 2 ,3 for and c, and d 456.
upvoted 4 times
...
lucaverce
2 years, 1 month ago
Selected Answer: C
C is correct, I tested it
upvoted 3 times
...
claudiodz
3 years, 3 months ago
adjust: echo '1 2 3 4 5 6' | while read a b c; do echo result $c $b $a; done
upvoted 2 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