The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-23-2006
kadishmj kadishmj is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 11
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:


Code:
#!/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?