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/ $//'; }
93 # enable history, bang history expansion, and emacs editing
99 LIM=.limbo # $HOME/$LIM contains "destroyed" objects
101 KNAP=.knapsack # $HOME/$KNAP contains objects being "carried"
103 then mkdir $KNAP >&- 2>&-
105 then echo 'You found a discarded empty knapsack.'
106 else echo 'You have no knapsack to carry things in.'
109 else echo 'One moment while I peek in your old knapsack...'
112 kn=`echo \`ls -a $KNAP | sed -e '/^\.$/d' -e '/^\.\.$/d'\``
114 if ask 'Welcome to the Adventure shell! Do you need instructions?'
117 echo -n 'Type a newline to continue: '
126 if [ $room != $prev ]
127 then if [ $room = $HOME ]
128 then echo 'You are in your own home.'
129 else echo "You have entered $room."
156 then echo 'This room contains:'
158 else echo 'The room looks empty.'
161 then echo 'There are exits labeled:'
163 echo 'as well as a passage overhead.'
164 else echo 'There is a passage overhead.'
167 then echo 'There are shadowy figures in the corner.'
172 read -e -p '-advsh> ' verb obj x # prompt is '-advsh> '
178 change) if [ "$obj" ]
179 then if ash_lk "$obs $hobs" "$obj"
184 then echo "You must destroy $2 first."
188 then if mv $obj $2 >&- 2>&-
189 then echo "The $obj shimmers and turns into $2."
190 obs=`ash_rm "$2 $obs" "$obj"`
191 else echo "There is a cloud of smoke but the $obj is unchanged."
197 *) echo "Change $obj to what?"
200 else if ash_lk "$kn" "$obj"
201 then echo 'You must drop it first.'
202 else echo "I see no $obj here."
205 else echo 'Change what?'
209 then if ash_lk "$obs $hobs" "$obj"
210 then if [ ! -r $obj ]
211 then echo "The $obj does not wish to be cloned."
216 then echo "You must destroy $2 first."
217 else if cp $obj $2 >&- 2>&-
218 then echo "Poof! When the smoke clears, you see the new $2."
220 else echo 'You hear a dull thud but no clone appears.'
226 *) echo "Clone $obj as what?"
230 else if ash_lk "$kn" "$obj"
231 then echo 'You must drop it first.'
232 else echo "I see no $obj here."
235 else echo 'Clone what?'
239 then for it in $obj $x
240 do if ash_lk "$kn" "$it"
242 then echo "You must destroy $it first."
243 else if mv $HOME/$KNAP/$it $it >&- 2>&-
244 then echo "$it: dropped."
245 kn=`ash_rm "$kn" "$it"`
247 else echo "The $it is caught in your knapsack."
250 else echo "You're not carrying the $it!"
253 else echo 'Drop what?'
256 enter|go) if [ "$obj" ]
257 then if [ $obj != up ]
258 then if ash_lk "$exs $hexs" "$obj"
261 then echo 'You squeeze through the passage.'
262 else echo "You can't go that direction."
264 else echo 'An invisible force blocks your way.'
266 else echo 'I see no such passage.'
269 then echo 'You struggle upwards.'
270 else echo "You can't reach that high."
273 else echo 'Which passage?'
276 examine) if [ "$obj" ]
277 then if [ $obj = all ]
278 then $obj=`echo $obs $exs`
282 do if ash_lk "$obs $hobs $exs $hexs" "$it"
283 then echo "Upon close inspection of the $it, you see:"
286 then echo "-- when you look directly at the $it, it vanishes."
288 else if ash_lk "$kn" "$it"
289 then echo 'You must drop it first.'
290 else echo "I see no $it here."
294 else echo 'Examine what?'
298 then if ash_lk "$obs $hobs" "$obj"
303 if PATH=$OPATH $* <$obj 2>&-
304 then echo "The $1 monster devours your $obj."
305 if rm -f $obj >&- 2>&-
306 then obs=`ash_rm "$obs" "$obj"`
307 else echo 'But he spits it back up.'
309 else echo "The $1 monster holds his nose in disdain."
314 *) echo "Feed $obj to what?"
317 else if ash_lk "$kn" "$obj"
318 then echo 'You must drop it first.'
319 else echo "I see no $obj here."
322 else echo 'Feed what?'
325 get|take) if [ "$obj" ]
326 then if [ $obj = all ]
331 do if ash_lk "$obs $hobs" "$it"
332 then if ash_lk "$kn" "$it"
333 then echo 'You already have one.'
334 else if mv $it $HOME/$KNAP/$it >&- 2>&-
335 then echo "$it: taken."
337 obs=`ash_rm "$obs" "$it"`
338 else echo "The $it is too heavy."
341 else echo "I see no $it here."
344 else echo 'Get what?'
347 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.'
348 cat | mail $MAINT -s 'ash bug'
353 inventory|i) if [ "$kn" ]
354 then echo 'Your knapsack contains:'
356 else echo 'You are poverty-stricken.'
359 kill|destroy) if [ "$obj" ]
360 then if [ $obj = all ]
362 if ask "Do you really want to attempt to $verb them all?"
369 do if ash_lk "$obs $hobs" "$it"
370 then if mv $it $HOME/$LIM <&- >&- 2>&-
371 then if [ $verb = kill ]
372 then echo "The $it cannot defend himself; he dies."
373 else echo "You have destroyed the $it; it vanishes."
375 obs=`ash_rm "$obs" "$it"`
376 else if [ $verb = kill ]
377 then echo "Your feeble blows are no match for the $it."
378 else echo "The $it is indestructible."
381 else if ash_lk "$kn" "$it"
382 then echo "You must drop the $it first."
384 else echo "I see no $it here."
388 else echo 'Kill what?'
391 look|l) obs=`echo $obs $hobs`
394 then echo 'The room contains:'
396 else echo 'The room is empty.'
398 exs=`echo $exs $hexs`
401 then echo 'There are exits plainly labeled:'
403 echo 'and a passage directly overhead.'
404 else echo 'The only exit is directly overhead.'
407 magic) if [ "$obj" = mode ]
409 then echo 'You had your chance and you blew it.'
410 else if ask 'Are you a wizard?'
411 then echo -n 'Prove it! Say the magic word: '
413 if [ "$obj" = armadillo ]
414 then echo 'Yes, master!!'
416 else echo "Homie says: I don't think so"
419 else echo "I didn't think so."
422 else echo 'Nice try.'
425 open|read) if [ "$obj" ]
426 then if ash_lk "$obs $hobs" "$obj"
429 then echo "Opening the $obj reveals:"
432 then echo '-- oops, you lost the contents!'
434 else echo "There is nothing inside the $obj."
436 else echo "You do not have the proper tools to open the $obj."
438 else if ash_lk "$kn" "$obj"
439 then echo 'You must drop it first.'
441 else echo "I see no $obj here."
444 else echo 'Open what?'
447 quit|exit) if ask 'Do you really want to quit now?'
449 then echo 'The contents of your knapsack will still be there next time.'
452 echo 'See you later!'
456 resurrect) if [ "$obj" ]
457 then for it in $obj $x
458 do if ash_lk "$obs $hobs" "$it"
459 then echo "The $it is already alive and well."
460 else if mv $HOME/$LIM/$it $it <&- >&- 2>&-
461 then echo "The $it staggers to his feet."
463 else echo "There are sparks but no $it appears."
467 else echo 'Resurrect what?'
471 then if ash_lk "$obs $hobs" "$obj"
472 then echo 'There is already one here.'
477 if PATH=$OPATH $* >$obj 2>&-
478 then echo "The $1 monster drops the $obj."
480 else echo "The $1 monster runs away as you approach."
483 else echo 'From what?'
486 *) echo "Steal $obj from what?"
490 else echo 'Steal what?'
494 then if ash_lk "$obs $hobs" "$obj"
498 daemon) if sh -c "lpr -r $obj"
499 then echo "The daemon catches the $obj, turns it into paper,\nand leaves it in the basket."
500 obs=`ash_rm "$obs" "$obj"`
501 else echo "The daemon is nowhere to be found."
508 *) echo "Throw $obj at what?"
511 else if ash_lk "$kn" "$obj"
512 then echo 'It is in your knapsack.'
514 else echo "I see no $obj here."
517 else echo 'Throw what?'
521 then echo 'You pull yourself up a level.'
522 else echo "You can't reach that high."
526 then echo "You awaken the $obj monster:"
528 echo 'The monster slithers back into the darkness.'
529 else echo 'Wake what?'
532 w|where) echo "You are in $room."
535 then echo 'A strange feeling comes over you.'
536 else echo 'Your spell fizzles out.'
541 then PATH=$OPATH $verb $obj $x
542 else echo "I don't know how to \"$verb\"."
543 echo 'Type "help" for assistance.'
545 else echo 'Say something!'