For loop variable to take value linewise, not word-wise

Hi All,

Please consider the below scenario.

/home/pranav> cat > abc.txt
abc def
xyz 123
/home/pranav>
/home/pranav> cat > test_for.ksh
#!/bin/ksh

for i in `cat abc.txt`
do
echo $i
done
/home/pranav>
/home/pranav> ksh test_for.ksh
abc
def
xyz
123
/home/pranav>

The point I am tryign to make is that, 'abc' 'def' are in the same line, the for variable is taking these values separately.

I want that the for variable, [$i in the above example] should take up values like 'abc def' and 'xyz 123' and not each wod separately.

Note: The loop should as many times as there are lines in the file [2 times aove example] and not the number of words [4 times as shown above].

#!/bin/ksh

while i=$(line)
do
  echo $i
done < abc.txt

while read line
do
echo $line
done < file_name

it did just what I needed.. will egt back in case of any further extensions to the same.

till then.. ciao!

Can be stripped down a little further:

while read
do
    echo $REPLY
done < file_name

I have a problem with 'while'
I am trying to set variables by 'while' and it is fine inside, but after complettig the loop all changes are lost:

> bb="kkkk-111\nlllll-22222\nbbbb-4444"
> echo "$bb"
kkkk-111
lllll-22222
bbbb-4444
> nn=""
> echo "$bb"|while read ln; do 
  nn=$nn", "$(echo $ln|cut -d- -f2); 
  echo $nn; 
done; 
echo "otside: \n$nn"
, 111
, 111, 22222
, 111, 22222, 4444
otside:
>

After 'while' internal changes are lost!
Is it how it should be?
It seems as 'while' is processing in separated shell.
Is here any way to make it works for lokal variables?

The 'for ..' loop works different"

> nn=""
> for ln in $(ec "$bb"|nawk 'NF {print "\""$0"\"";}'); do 
  nn=$nn", "$(ec $ln|sed 's/"//'|cut -d- -f2); 
  ec $nn; 
done; 
ec "otside: \n$nn"
, 111"
, 111", 22222"
, 111", 22222", 4444"
otside:
, 111", 22222", 4444"
>

Your script should just work with ksh.
I guess you are using bash which use a subshell for the wrong (IMHO) side of a pipe ...

Thank you jlliagre, you are right!

> ksh
> n=0; cat ff|while read ll; do echo "now $ll"; n=$n", "$ll; done; echo $n
now 11
now 222
now 333
0, 11, 222, 333
> ^D
> it is bash now
bash: it: command not found
> n=0; cat ff|while read ll; do echo "now $ll"; n=$n", "$ll; done; echo $n
now 11
now 222
now 333
0
> n=0; while read ll; do echo "now $ll"; n=$n", "$ll; done <ff; echo $n
now 11
now 222
now 333
0, 11, 222, 333
>

Sad!
Bash has been so nice for me!