bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Builtin 'read' data not saved


From: Chet Ramey
Subject: Re: Builtin 'read' data not saved
Date: Thu, 02 Jan 2014 21:14:47 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 1/2/14, 2:35 PM, P Fudd wrote:
> 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="

This is a bug in bash-4.2.  The expansion of $R is not supposed to be
subject to the value of IFS.  You can read a discussion of the issue here:

http://lists.gnu.org/archive/html/bug-bash/2013-01/msg00041.html

> ====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

A and B will be unset when the second `read' hits EOF and returns failure,
breaking the loop.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]