[Top][All Lists]

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

Re: [Help-bash] Is there a way to read empty string with `read`?

From: Greg Wooledge
Subject: Re: [Help-bash] Is there a way to read empty string with `read`?
Date: Mon, 23 May 2016 09:45:06 -0400
User-agent: Mutt/

On Mon, May 23, 2016 at 07:18:16AM -0500, Peng Yu wrote:
> Hi, The following code shows that an empty string between two TABs can
> not be captured. Is there a way to let bash read empty strings between
> TABs?

Convert the tab characters to some other character that is not treated
as whitespace by IFS, and which also does not appear in the input data.

echo $'one\ttwo\t\tfour' > testfile
while IFS=$'\002' read -ra array; do
    declare -p array
done < <(tr \\t \\002 < testfile)

Multiple consecutive whitespace characters are treated as a single
delimiter by IFS.  This is by design, as it's what you want 99% of the
time, for input files that have fields padded by whitespace.

reply via email to

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