1 Feb 2010 01:36
Re: Retaining leading white space when passing string values.
Todd A. Jacobs wrote:
> On Sun, Jan 31, 2010 at 02:18:17PM -0800, Ray Parrish wrote:
>
>
>> Why??? It also does not work if I echo ${LineData[LoopCount]}... all
>> of the leading spaces disappear.
>>
>
> I think it's because the read bash built-in is using IFS to split words,
> which is one of the reasons I suggested treating the string as a stream
> rather than as a read loop. See this:
>
> http://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html
>
> for why you're losing spaces. Of course, if you're trying to concatenate
> lines, losing the spaces is actually a Good Thing (tm), but if you
> really need them, read on.
>
> You can fix this by setting IFS to an empty string, but that might mess
> up something else in your script later on unless you unset IFS again
> after the while loop.
>
> So:
>
> IFS=''
> while read; do
> :
> done
> unset IFS
>
(Continue reading)
RSS Feed