- 论坛徽章:
- 0
|
[root@localhost root]# vi ./party
#!/bin/tcsh -f
# TC shell
# The Party Program--Invitations to friends from the "guest" file
set guestfile = ~/shell/guests
if (! -e "$guestfile" then
echo "$guestfile:t non-existent"
exit 1
endif
set env PLACE "Sarotini's"
@ Time= `date +%H` +1
set food = (cheese crackers shrimp drinks "hot dogs" sandwiches)
foreach person (`cat $guestfile`)
if ($person = ~root)continue
#Start of here document
mail -v -s " arty" $person << FINIS
Hi ${person}! Please join me at $PLACE for a party!
Meet me at $Time o'clock.
I'll bring the ice cream. Would you please bring $food[1] and anything else you would like to eat? Let me know if you can't make
it. Hope to see you soon.
Your pal,
star@`hostname`
FINIS
shift food
if ($#food == 0)then
set food = (cheese crackers shrimp drinks "hot dogs" sandwiches)
end if
end
echo "Bye..."
[root@localhost root]# ./party
set: Variable name must begin with a letter.
目的:向一系列用户发送信息。邀请他们参加一个party。party的时间和地点被存入变量,被邀请的人是从一个叫做guests的文件中选出来的。食物清单保存在一个单词列表里,每一个都要求从清单中选择一种食物。如时选择同样食物的用户多于该食物的项目数量,清单就被重置,每一个用户就被要求重新选择另一种食物。惟一没有被邀请的用户是root. |
|