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
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
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'.
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
Thanks for the explanation :)
thanks man
I'm not understanding why C gets the rest of the values (3456) :(
did you find out?
Thanks for the explanation :)
$ 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
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.
C is correct, I tested it
adjust: echo '1 2 3 4 5 6' | while read a b c; do echo result $c $b $a; done
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"
Tricky one
C is correct