C shell question about foreach
Greg Hunt
hunt at dg-rtp.rtp.dg.com
Thu Jun 6 03:34:20 AEST 1991
In article <11842 at hub.ucsb.edu>, 6600bori at 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 at 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.
More information about the Comp.unix.questions
mailing list