[ILUGC] Re: help to understand this bash output

  • From: M K Saravanan <mksarav@xxxxxxxxx>
  • To: ilugc@xxxxxxxxxxxxx
  • Date: Sun, 15 Jan 2023 21:38:13 +0800

$ 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
When executing line one, I am expecting the output to be:

1 2 3 4 5 6

SO during reading, I am assuming, a,b,c will take the values 1 2 3
respectively. so the next echo will print:

result: 3 2 1
the while loop will go to another round and read the remaining 3 values and
hence a b c will take the value 4,5,6 respectively and hence the result at
end be:

result: 3 2 1 6 5 4

But what is being printed is:

result: 3 4 5 6 2 1

So clearly I misunderstood something above in my logic. Hence asking for
help.

mks


---
Mailing List Guidelines: https://ilugc.in/mailing-list-guidelines
Web: http://ilugc.in/
Internet Relay Chat: #ilugc on libera.chat

Other related posts: