For Loop with Strings as parameters

I'm trying to create a script with a for loop that take strings in as the parameters. Some of the strings have spaces in them, and I can't get it to work properly. For example:

#!/bin/ksh

INFILE=snapshot.log
OUTFILE=summary.out

a="Lock waits"
b="Deadlocks detected"

for PARAM in ${a} ${b}
do
   /usr/bin/grep ${PARAM} ${INFILE} >> ${OUTFILE}
done

I want the loop to execute 2 times, but it is executing 4 times with the following values for PARAM:

1st pass - Lock
2nd pass - waits
3rd pass - Deadlocks
4th pass - detected

I've tried placing the strings in single and double quotes, but that doesn't seem to help. Any ideas?

I don�t know a lot of english and i will to try to explain it. If you have more questions you can ask again :wink: . Ok the system has a variable, that for loop uses to know how many parameters has the file for example a text. The variable has space, tabs and return (of course all convinations of that).

THE ANSWER

$cat > example
spaces=IFS #IFS is the system variable
IFS=" #We inicializating IFS=return to tae all the line
"
........................
........................
IFS=$spaces #We used the var spaces to give the value to IFS againwhen we finish
unset spaces

Bye

Thanks for looking at this Doc_RuNNeR, but I don't understand your solution

Try:

for PARAM in "${a}" "${b}"

#! /bin/ksh

spaces=IFS
IFS="
"
for i in "hello world"
do
echo $i
done
IFS=$spaces

-----------------

Try that script

Thanks for everyone's suggestions. I finally got it working:

OUTFILE=summary.out
a='Deadlocks detected'
b='Lock escalations'

for PARAM in "${a}" "${b}"
do

 echo ${PARAM}

 COUNT=1

   while ((COUNT < 41))
   do
      INFILE=DB2Snapshot_${1}_${COUNT}.log
      /usr/bin/grep "${PARAM}" ${INFILE} >> ${OUTFILE}

   ((COUNT=COUNT+1))
   done
done

Hi ,

I am getting similar problem,
but in my case i am fetching variable value from a file , and then echo the value, but its considering spaces in the file. for exmp:

file - temp1 has contents in quotes
"group name used to communicate with x service"
"group name used to communicate with y service"

i used for loop :
for var in `cat "temp1"`
do
echo "DESC=$var;"
done

the desired output is
DESC="group name used to communicate with x service";
DESC="group name used to communicate with y service";

however, the output coming is
DESC="group";
DESC="name";

its reading spaces also...

Pls suggest...............

Thanks in advance
Aparna