On Thu, 16 Jul 1998 13:20:16 -0400, Timothy J Luoma
<luomat+Lists/Unix/procmail(_at_)luomat(_dot_)peak(_dot_)org> wrote:
for i in `cat $USERS`
do
Shell programming issue: You mean
while read i; do
...
done <$USERS
or, if $USERS expands to more than one file,
cat $USERS |
while read i; do
...
done
Why? Because (1) it saves a process, in the first case (Useless Use of
Cat Award! <http://www.iki.fi/~era/unix/award.html>), and (2) there
really is a risk that the output from the backticks hits the limits
for how long an argument list your shell can take on the command line.
Try the following:
$ cpp <<HERE | grep '^[1-9]'
#include <limits.h>
ARG_MAX
HERE
38912
On SunOS, you'd get something like a megabyte, but even that can be
exceeded if $USERS is big enough. (POSIX requires 4096 bytes. The
smallest I've seen [okay, read about] is 1024.)
However, it would be much more efficient to not call sendmail all those
times, just make it one long line:
Mail -s "Your Subject Line Here" `cat /tmp/list` < /tmp/message
For similar reasons, this is dangerous. You can try to fool around
with xargs, or just break down and write a temporary script. Better
yet, if you intend to do this on a regular basis, use a real mailing
list manager such as SmartList.
man xargs, or look at comp.unix.shell in DejaNews until you feel
nauseous.
Obviously, for a one-shot job where you +know+ the files are small,
these comments are off the wall. I'm primarily reacting against the
use of "for f in `cat in backticks`", which is practically always
wrong.
Hope this helps,
/* era */
--
Paparazzi of the Net: No matter what you do to protect your privacy,
they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>