I'm writing a Bash script to read from an input file and write my changes out to an output file. I'm using read and for some reason, it is stripping the leading spaces off of each line. I didn't see any flags in read to turn the stripping off. I'm also runnig this in cygwin, but I don't think that should matter.

The code I am using is something like this.
while read curline;
do
echo "current line " $curline
if [ ! -z "$curline" ]; then
while read outline;
do
echo "$curline" >> $Output_Work
fi
done < $Input_Work

Am I doing something wrong here?

thanks,

Jerome

In my very limited scripting experience, read will ignore spaces. You might be able to change that but I don't know how.

I have a read question, too, in another thread I just posted.

[...]
I'm using read and for some reason, it is stripping the leading spaces off of each line.
[...]

Consider this:

$ cat infile
a
 a
        a
$ while read;do
while> echo "$REPLY"
while> done<infile
a
a
a
$ while IFS= read;do
echo "$REPLY"
done<infile
a
 a
        a
$
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.