102-500 Exam QuestionsBrowse all questions from this exam

102-500 Exam - Question 43


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

Show Answer
Correct Answer: C

The command 'echo '1 2 3 4 5 6' | while read a b c; do echo result $c $b $a; done' splits the input string '1 2 3 4 5 6' by spaces and assigns '1' to variable 'a', '2' to variable 'b', and the rest of the values '3 4 5 6' to variable 'c'. The echo command within the loop prints the variables in the order $c, $b, $a, resulting in the output '3 4 5 6 2 1'.

Discussion

8 comments
Sign in to comment
mustacheOption: C
Aug 19, 2020

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

iwkno6
Aug 28, 2021

Thanks for the explanation :)

jegga
Nov 9, 2021

thanks man

MaikyCR28
Jun 10, 2022

I'm not understanding why C gets the rest of the values (3456) :(

bestiutza
Oct 21, 2022

did you find out?

thanux
Jul 20, 2022

Thanks for the explanation :)

brrbrrOption: C
Jul 24, 2020

$ 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

bestiutzaOption: E
Oct 23, 2022

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.

lucaverceOption: C
May 26, 2022

C is correct, I tested it

claudiodzOption: A
Mar 28, 2021

adjust: echo '1 2 3 4 5 6' | while read a b c; do echo result $c $b $a; done

kleverOption: C
Jan 10, 2023

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"

M_ukesh8
Dec 4, 2023

Tricky one

fjcsanchezOption: C
Mar 3, 2024

C is correct