0

The following bash does not print out var text, which is confusing to me. How to print the value of text?

text=D
echo -e 'A\nB\nC' | while read aline; do
text=$aline 
done
echo $text

the printout is D, but I want to print value C.

Richard
  • 14,642
  • 18
  • 56
  • 77
  • 1
    BashFAQ #24: http://mywiki.wooledge.org/BashFAQ/024 – Charles Duffy Jul 24 '15 at 01:34
  • On a side note, `printf '%s\n' A B C` is the better way to print the given stream; any shell in which `echo -e` does something other than print `-e` on its output is explicitly violating the POSIX spec. – Charles Duffy Jul 24 '15 at 01:54

0 Answers0