Csh & foreach causing fork problems

Howard Chu hyc at hanauma.jpl.nasa.gov
Tue Mar 26 10:06:50 AEST 1991


In article <1991Mar24.201730.14808 at aucs.AcadiaU.ca> 880274d at 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!



More information about the Comp.unix.questions mailing list