Builtin 'read' data not saved

2014-01-02 Thread P Fudd
Hello all,

I'm at my wit's end.  This script is not working:
=
#!/bin/bash
B=none
echo "2" | while read -r A; do
  B="$A"
  echo 1.B=$B
done
echo 2.B=$B
==
The output, from GNU bash, version 4.2.25(1)-release
(x86_64-pc-linux-gnu), bash-4.2-2ubuntu2.1.deb, is this:

1.B=2
2.B=none

I'm baffled; it's like the while loop is in a parallel universe.  I tried
'export B=none' in line 2, with no effect.

Help?
--
f...@ch.pkts.ca



Re: Builtin 'read' data not saved

2014-01-02 Thread P Fudd
Here's some more oddities:

=failing.sh:
#!/bin/bash
R="1|2"
IFS='|' read -r A B <<< $R
echo A=$A, B=$B

Expected: "A=1, B=2"
Actual: "A=1 2, B="


fail2.sh:
#!/bin/bash
R="1|2"
while IFS='|' read -r A B; do
echo 1:A=$A, B=$B
done <<< $R
echo 2:A=$A, B=$B

Expected:
  1:A=1, B=2
  2:A=1, B=2
Actual:
  1:A=1, B=2
  2:A=, B=


GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
bash-4.2-2ubuntu2.1.deb

Cheers!
--
f...@ch.pkts.ca
Thanks!