help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] IFS & read


From: Dan Douglas
Subject: Re: [Help-bash] IFS & read
Date: Sat, 26 May 2012 14:24:42 -0500
User-agent: KMail/4.8.3 (Linux/3.3.6-pf+; KDE/4.8.3; x86_64; ; )

On Saturday, May 26, 2012 12:56:31 PM Bill Gradwohl wrote:
> I have a file that uses the tab character as the separator.
> 
> Writing a read loop against that file works just fine and I get field
> separation.
> 
> I converted that file by replacing the tab character with \b and changed
> the IFS to match and now I don't get field separation.
> 
> I also tried \x00 and \x01 and they don't work either.

You can't put a NUL byte into a variable. Don't know about your \x01 case. For 
reading a nul-delimited string you have to use -d. See:

http://lists.gnu.org/archive/html/bug-bash/2011-11/msg00148.html

> What are the allowable IFS characters as far as read is concerned?
Anything but NUL.

$ LC_CTYPE=C printf '%x\n' $'\'\b'
8
$ printf '%q' "$(printf '\x8%s' {1..5})"; echo
$'\b1\b2\b3\b4\b5'
$ printf '\x8%s' {1..5} | while read -rd $'\b' 'x[n++]'; do :; done; echo 
"address@hidden"
1 2 3 4 5
$ printf '\x8%s' {1..5} | IFS=$'\b' read -ra 'x'; echo "address@hidden"
1 2 3 4 5

Also amongst the shells that have a -d, there is some variance in behavior. 
Bash seems to do things as I expect with -d more often than the others.
-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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