2 # ash -- "Adventure shell"
3 # last edit: 86/04/21 D A Gwyn
4 # SCCS ID: @(#)ash.sh 1.4
29 Instructions for the Adventure shell
31 Welcome to the Adventure shell! In this exploration of the UNIX file
32 system, I will act as your eyes and hands. As you move around, I will
33 describe whatever is visible and will carry out your commands. The
34 general form of a command is
35 Verb Object Extra_stuff.
36 Most commands pay no attention to the "Extra_stuff", and many do not
37 need an "Object". A typical command is
39 which picks up all files in the current "room" (directory). You can
40 find out what you are carrying by typing the command
42 The command "help" results in a full description of all commands that I
43 understand. To quit the Adventure shell, type
46 There are UNIX monsters lurking in the background. These are also
47 known as "commands with arguments".
55 echo "I understand the following commands (synonyms in parentheses):"
58 echo "change OBJECT to NEW_NAME changes the name of the object"
59 echo "clone OBJECT as NEW_NAME duplicates the object"
60 echo "drop OBJECTS leaves the objects in the room"
61 echo "enter (go) PASSAGE takes the labeled passage"
62 echo "examine OBJECTS describes the objects in detail"
63 echo "feed OBJECT to MONSTER stuffs the object into a UNIX monster"
64 echo "get (take) OBJECTS picks up the specified objects"
65 echo "gripe (bug) report a problem with the Adventure shell"
66 echo "help prints this summary"
67 echo "inventory (i) tells what you are carrying"
68 echo "kill (destroy) OBJECTS destroys the objects"
69 echo "look (l) describes the room, including hidden objects"
70 echo "open (read) OBJECT shows the contents of an object"
71 echo "quit (exit) leaves the Adventure shell"
72 echo "resurrect OBJECTS attempts to restore dead objects"
73 echo "steal OBJECT from MONSTER obtains the object from a UNIX monster"
74 echo "throw OBJECT at daemon feeds the object to the printer daemon"
75 echo "up takes the overhead passage"
76 echo "wake MONSTER awakens a UNIX monster"
77 echo "where (w) tells you where you are"
78 echo "xyzzy moves you to your home"
81 MAINT=chet@ins.cwru.edu
83 PATH=/usr/ucb:/bin:/usr/bin:/usr/local/bin:.
87 #trap '' 18 # disable Berkeley job control
89 ash_lk(){ echo " $1 " | fgrep " $2 " >&- 2>&-; }
90 ash_pr(){ echo $* | tr ' ' '\012' | pr -5 -t -w75 -l$[ ( $# + 4 ) / 5 ]; }
91 ash_rm(){ echo " $1 " | sed -e "s/ $2 / /" -e 's/^ //' -e 's/ $//'; }
94 LIM=.limbo # $HOME/$LIM contains "destroyed" objects
96 KNAP=.knapsack # $HOME/$KNAP contains objects being "carried"
98 then mkdir $KNAP >&- 2>&-
100 then echo 'You found a discarded empty knapsack.'
101 else echo 'You have no knapsack to carry things in.'
104 else echo 'One moment while I peek in your old knapsack...'
107 kn=`echo \`ls -a $KNAP | sed -e '/^\.$/d' -e '/^\.\.$/d'\``
109 if ask 'Welcome to the Adventure shell! Do you need instructions?'
112 echo -n 'Type a newline to continue: '
121 if [ $room != $prev ]
122 then if [ $room = $HOME ]
123 then echo 'You are in your own home.'
124 else echo "You have entered $room."
151 then echo 'This room contains:'
153 else echo 'The room looks empty.'
156 then echo 'There are exits labeled:'
158 echo 'as well as a passage overhead.'
159 else echo 'There is a passage overhead.'
162 then echo 'There are shadowy figures in the corner.'
167 echo -n '-advsh> ' # prompt
174 change) if [ "$obj" ]
175 then if ash_lk "$obs $hobs" "$obj"
180 then echo "You must destroy $2 first."
184 then if mv $obj $2 >&- 2>&-
185 then echo "The $obj shimmers and turns into $2."
186 obs=`ash_rm "$2 $obs" "$obj"`
187 else echo "There is a cloud of smoke but the $obj is unchanged."
193 *) echo "Change $obj to what?"
196 else if ash_lk "$kn" "$obj"
197 then echo 'You must drop it first.'
198 else echo "I see no $obj here."
201 else echo 'Change what?'
205 then if ash_lk "$obs $hobs" "$obj"
206 then if [ ! -r $obj ]
207 then echo "The $obj does not wish to be cloned."
212 then echo "You must destroy $2 first."
213 else if cp $obj $2 >&- 2>&-
214 then echo "Poof! When the smoke clears, you see the new $2."
216 else echo 'You hear a dull thud but no clone appears.'
222 *) echo "Clone $obj as what?"
226 else if ash_lk "$kn" "$obj"
227 then echo 'You must drop it first.'
228 else echo "I see no $obj here."
231 else echo 'Clone what?'
235 then for it in $obj $x
236 do if ash_lk "$kn" "$it"
238 then echo "You must destroy $it first."
239 else if mv $HOME/$KNAP/$it $it >&- 2>&-
240 then echo "$it: dropped."
241 kn=`ash_rm "$kn" "$it"`
243 else echo "The $it is caught in your knapsack."
246 else echo "You're not carrying the $it!"
249 else echo 'Drop what?'
252 enter|go) if [ "$obj" ]
253 then if [ $obj != up ]
254 then if ash_lk "$exs $hexs" "$obj"
257 then echo 'You squeeze through the passage.'
258 else echo "You can't go that direction."
260 else echo 'An invisible force blocks your way.'
262 else echo 'I see no such passage.'
265 then echo 'You struggle upwards.'
266 else echo "You can't reach that high."
269 else echo 'Which passage?'
272 examine) if [ "$obj" ]
273 then if [ $obj = all ]
274 then $obj=`echo $obs $exs`
278 do if ash_lk "$obs $hobs $exs $hexs" "$it"
279 then echo "Upon close inspection of the $it, you see:"
282 then echo "-- when you look directly at the $it, it vanishes."
284 else if ash_lk "$kn" "$it"
285 then echo 'You must drop it first.'
286 else echo "I see no $it here."
290 else echo 'Examine what?'
294 then if ash_lk "$obs $hobs" "$obj"
299 if PATH=$OPATH $* <$obj 2>&-
300 then echo "The $1 monster devours your $obj."
301 if rm -f $obj >&- 2>&-
302 then obs=`ash_rm "$obs" "$obj"`
303 else echo 'But he spits it back up.'
305 else echo "The $1 monster holds his nose in disdain."
310 *) echo "Feed $obj to what?"
313 else if ash_lk "$kn" "$obj"
314 then echo 'You must drop it first.'
315 else echo "I see no $obj here."
318 else echo 'Feed what?'
321 get|take) if [ "$obj" ]
322 then if [ $obj = all ]
327 do if ash_lk "$obs $hobs" "$it"
328 then if ash_lk "$kn" "$it"
329 then echo 'You already have one.'
330 else if mv $it $HOME/$KNAP/$it >&- 2>&-
331 then echo "$it: taken."
333 obs=`ash_rm "$obs" "$it"`
334 else echo "The $it is too heavy."
337 else echo "I see no $it here."
340 else echo 'Get what?'
343 gripe|bug) echo 'Please describe the problem and your situation at the time it failed.\nEnd the bug report with a line containing just a Ctrl-D.'
344 cat | mail $MAINT -s 'ash bug'
349 inventory|i) if [ "$kn" ]
350 then echo 'Your knapsack contains:'
352 else echo 'You are poverty-stricken.'
355 kill|destroy) if [ "$obj" ]
356 then if [ $obj = all ]
358 if ask "Do you really want to attempt to $verb them all?"
365 do if ash_lk "$obs $hobs" "$it"
366 then if mv $it $HOME/$LIM <&- >&- 2>&-
367 then if [ $verb = kill ]
368 then echo "The $it cannot defend himself; he dies."
369 else echo "You have destroyed the $it; it vanishes."
371 obs=`ash_rm "$obs" "$it"`
372 else if [ $verb = kill ]
373 then echo "Your feeble blows are no match for the $it."
374 else echo "The $it is indestructible."
377 else if ash_lk "$kn" "$it"
378 then echo "You must drop the $it first."
380 else echo "I see no $it here."
384 else echo 'Kill what?'
387 look|l) obs=`echo $obs $hobs`
390 then echo 'The room contains:'
392 else echo 'The room is empty.'
394 exs=`echo $exs $hexs`
397 then echo 'There are exits plainly labeled:'
399 echo 'and a passage directly overhead.'
400 else echo 'The only exit is directly overhead.'
403 magic) if [ "$obj" = mode ]
405 then echo 'You had your chance and you blew it.'
406 else if ask 'Are you a wizard?'
407 then echo -n 'Prove it! Say the magic word: '
409 if [ "$obj" = armadillo ]
410 then echo 'Yes, master!!'
412 else echo "Homie says: I don't think so"
415 else echo "I didn't think so."
418 else echo 'Nice try.'
421 open|read) if [ "$obj" ]
422 then if ash_lk "$obs $hobs" "$obj"
425 then echo "Opening the $obj reveals:"
428 then echo '-- oops, you lost the contents!'
430 else echo "There is nothing inside the $obj."
432 else echo "You do not have the proper tools to open the $obj."
434 else if ash_lk "$kn" "$obj"
435 then echo 'You must drop it first.'
437 else echo "I see no $obj here."
440 else echo 'Open what?'
443 quit|exit) if ask 'Do you really want to quit now?'
445 then echo 'The contents of your knapsack will still be there next time.'
448 echo 'See you later!'
452 resurrect) if [ "$obj" ]
453 then for it in $obj $x
454 do if ash_lk "$obs $hobs" "$it"
455 then echo "The $it is already alive and well."
456 else if mv $HOME/$LIM/$it $it <&- >&- 2>&-
457 then echo "The $it staggers to his feet."
459 else echo "There are sparks but no $it appears."
463 else echo 'Resurrect what?'
467 then if ash_lk "$obs $hobs" "$obj"
468 then echo 'There is already one here.'
473 if PATH=$OPATH $* >$obj 2>&-
474 then echo "The $1 monster drops the $obj."
476 else echo "The $1 monster runs away as you approach."
479 else echo 'From what?'
482 *) echo "Steal $obj from what?"
486 else echo 'Steal what?'
490 then if ash_lk "$obs $hobs" "$obj"
494 daemon) if sh -c "lpr -r $obj"
495 then echo "The daemon catches the $obj, turns it into paper,\nand leaves it in the basket."
496 obs=`ash_rm "$obs" "$obj"`
497 else echo "The daemon is nowhere to be found."
504 *) echo "Throw $obj at what?"
507 else if ash_lk "$kn" "$obj"
508 then echo 'It is in your knapsack.'
510 else echo "I see no $obj here."
513 else echo 'Throw what?'
517 then echo 'You pull yourself up a level.'
518 else echo "You can't reach that high."
522 then echo "You awaken the $obj monster:"
524 echo 'The monster slithers back into the darkness.'
525 else echo 'Wake what?'
528 w|where) echo "You are in $room."
531 then echo 'A strange feeling comes over you.'
532 else echo 'Your spell fizzles out.'
537 then PATH=$OPATH $verb $obj $x
538 else echo "I don't know how to \"$verb\"."
539 echo 'Type "help" for assistance.'
541 else echo 'Say something!'