For Loop help with patchrm Solaris 10

Hello all

looking to write a for loop to remove patches in the /var/sadm/patch directory. So far this is what i have:

#! /bin/sh

cd /var/sadm/patch

ls -l | awk '{print $9}' > patches

/usr/bin/sort -r patches > patches_r

for i in 'cat patches_r'
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done

echo "All patches should be removed"

i receive the error when it gets to the for loop. it errors on 'cat patches_r' and claims there is no patch named cat or patches_r?

still new to shell scripting, can someone explain where this is messing up??

Thanks

Use backticks , not single-quote.

for i in `cat patches_r`
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done

... and don't try to win the Useless Use of Cat Award

while read i
  do 
    echo "going to remove patch $i"

            /usr/sbin/patchrm $i
done < patches_r

you need to use `and not '. better is to use $(command).

what do you mean the useless use of cat award? Would you suggest using something else?

the second code IS the better solution!

Let's remember what is Useless Use of Cat Award :wink:

wow, ok. Thanks for that bit of UNIX history. Makes sense and i appreciate it. In fact, that entire page is pretty good.