Reputation: 13
I'm waiting that response of this expression
1..2 | foreach { echo $_; $_ } | foreach { $_*$_ }
be like
1
1
2
4
but receive
1
1
4
4
So i dont understand why is this happends.
Upvotes: 1
Views: 79
Reputation: 27453
Echo sends its output to the 2nd foreach. I think you want to use write-host, which doesn't send its output to the rest of the pipeline. Echo would do the same thing in cmd or bash.
1..2 | foreach { write-host $_; $_ } | foreach { $_*$_ }
1
1
2
4
Upvotes: 1