0

I have a file containing a list of process is input1 file

proc1
proc2 b
proc3 a

I use the following command to read the file and pass on the content of the file to a variable and then do something

for in in cat `input1`;do 
echo $i
done

It works fine for entries like proc1. But the problem is that it assigns only the proc2 to the variable $i and the also assign b to to $i etc etc .. How can I pass the entire proc2 b to variable $i with the space in between ????

Thanks

theuniverseisflat
  • 821
  • 2
  • 12
  • 18

1 Answers1

0
$ while IFS= read i; do echo $i; done <input1
proc1
proc2 b
proc3 a


$ IFS=$'\n'; for i in $(cat input1); do echo $i; done
proc1
proc2 b
proc3 a

Update: From the comments, it appears that you want to pass the name of a file from an outer loop to an inner loop which will read from the file. In that case:

for fname in input1 input2
do
    while IFS= read i
    do 
        echo $i
    done <"$fname"
done

Or, if the file names are being read from a file called filelist:

while IFS= read fname
do 
    while IFS= read i
    do
        echo 1=$i
    done <"$fname"
done <filelist
John1024
  • 103,964
  • 12
  • 124
  • 155