Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!dg-rtp!hunt From: hunt@dg-rtp.rtp.dg.com (Greg Hunt) Newsgroups: comp.unix.questions Subject: Re: C shell question about foreach Keywords: csh, foreach Message-ID: <1991Jun5.173420.29478@dg-rtp.dg.com> Date: 5 Jun 91 17:34:20 GMT References: <11842@hub.ucsb.edu> Sender: hunt@hobbit.rtp.dg.com (Greg Hunt) Reply-To: hunt@dg-rtp.rtp.dg.com Distribution: comp Organization: Data General Corp., Research Triangle Park, NC Lines: 41 In article <11842@hub.ucsb.edu>, 6600bori@ucsbuxa.ucsb.edu (Boris Burtin) writes: > I'm trying to write a csh script that will execute a series of commands for > every directory that exists in /home/pluto. This script works if I execute > it while I'm logged in, but it gives me a > > syntax error at line 7: `(' unexpected > > when I try to run it from crontab. I'd appreciate any help I can get! > Here's the code: > > -------- > # > > set people = `ls /home/pluto` > > foreach person($people[*]) > echo $person >> /tmp/test.txt > end Boris, I believe the problem is that scripts run via crontab are executed by sh by default instead of csh. You need to force the script to be executed by the csh by adding: #!/bin/csh as the first line of the script, assuming that your system recognizes this convention. Otherwise, you'll need to rewrite the script in sh instead of csh. Also, I don't think the [*] after $people is doing any good. $people is already a space separated list of words, and all the [*] says is to take all words. I think just $people will work equally as well. At least it does on my system with your example. Enjoy! -- Greg Hunt Internet: hunt@dg-rtp.rtp.dg.com DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt Data General Corporation Research Triangle Park, NC, USA These opinions are mine, not DG's.