The work around is to not have the pipe there - which is possible through process substitution.
echo -e "one\ntwo\nthree" | \ while read name; do val=$name; echo $val; done; echo $valThis outputs:
one two threeNotice that the final value "three" is not printed twice as 'val' no longer contains a value.
And the work around:
while read name; do val=$name; echo $val; done < <(echo -e "one\ntwo\nthree") echo $valwhich now outputs:
one two three threeSuccess! (or, if you're a "Bill and Ted's Bogus Journey" fan - Station!).