Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!jato!hanauma.jpl.nasa.gov!hyc From: hyc@hanauma.jpl.nasa.gov (Howard Chu) Newsgroups: comp.unix.questions Subject: Re: Csh & foreach causing fork problems Message-ID: <1991Mar26.000650.7380@jato.jpl.nasa.gov> Date: 26 Mar 91 00:06:50 GMT References: <1991Mar24.201730.14808@aucs.AcadiaU.ca> Sender: news@jato.jpl.nasa.gov Organization: SAR Systems Development and Processing, JPL Lines: 30 Nntp-Posting-Host: hanauma.jpl.nasa.gov In article <1991Mar24.201730.14808@aucs.AcadiaU.ca> 880274d@aucs.acadiau.ca (Ralph Doncaster) writes: >I'm having problems with a script I made to mail all the students on our >system. I often get a "fork: no more processes" error. >I assume this is because foreach starts a new process for each argument it is >given. >How can I solve this problem? >Here is the script: > >#!/bin/csh ># bm (batch mailer) by Ralph Doncaster, Jan 25/91 ># script to mail message to all accounts in /u/student ># usage: bm subject file >if ($#argv) then > foreach i(`/bin/ls /u/student`) > mail -s $1 $i < $2 > sleep 1 > end > echo "Sending message file " $1 "to all accounts in /u/student." >else > echo "Usage: bm subject file" >endif I'd replace this with an alias, something like: alias bm '(cd /u/student; set list=(*); mail -s \!:1 $list < \!:2)' Note that in any case, you must quote the subject that you specify if it's going to be more than 1 word. -- -- Howard Chu @ Jet Propulsion Laboratory, Pasadena, CA Disclaimer: How would I know, I just got here!