Help me understand this!
Bill Vermillion
fp at wjv.com
Wed Jul 21 13:14:27 PDT 2004
It was Wed, Jul 21 13:28 when Lerebours, Jose said "Mia kusenveturilo estas
plena da angiloj. And continued:
> >From filePro process, I am using
> x=open(file,"rwtc"), y=write(x,string) and z=close(x)
> Now, string holds value from two fields
> field1(10,*) and field2(13,*)
> content in field1 is mostly not longer than 8 char
> So, the written file ends-up looking like so
> 0123456789012345678901234567890
> FIELD1LN1 FIELD2LINE1
> FIELD1LN2 FIELD2LINE2
> FIELD1LN3 FIELD2LINE3
> etc, etc, etc ...
> I then use shell script to run a for/next loop
> for X in `cat filename`
> do
> echo "$X"
> done
> The displayed text is as follows
> FIELD1LN1
> FIELD1LINE1
> FIELD1LN2
> FIELD2LINE2
> FIELD1LN3
> FIELD2LINE3
> I am expecting to retain both fields side by side
> in $X. If I vi the file it looks fine. If I cat
> the file it looks fine ...
If you would read the man page for your typical shell you would
not expect this :-)
========================================
for vname [ in word ... ] ;do list ;done
Each time a for command is executed, vname is set to the next
word taken from the in word list. If in word ... is omitted,
then the for command executes the do list once for each posi-
tional parameter that is set starting from 1 (see Parameter
Expansion below). Execution ends when there are no more words
in the list.
========================================
> Why is this? How can I get what I am looking for?
The above explains it. X is being set for each word, not each
line.
Off the top of my head you might reset the IFS to be only
a newline before you start the script. Then set it back when the
script ends.
The man also states that if IFS is not set the default will
be <space>
BIll
--
Bill Vermillion - bv @ wjv . com
More information about the Filepro-list
mailing list