~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/maze/maze.sh -rw-r--r-- 751 bytes
fc214385Johan Vandegriff added other old scripts, some newer ones too 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

root=`dirname $0`

if [ ! -d $root/maze ]
then
    $root/makemaze.pl
fi
 
cd $root/maze

while true
do

  if [ -d E ]
  then
    echo
    cat $root/logo.txt
    echo
    echo "You found the end!"
    echo "Press ENTER to exit."
    read a
    exit 0
  fi

  echo

  ls -1

  echo
  echo "B (Back)"
  echo "Q (Quit)"
  echo "Location:"
  pwd | tr '/' 'X' | sed s/`echo $root | tr '/' 'X'`//g | tr 'X' '/'

  cat $root/logo.txt

  echo -n 'Please choose one of the above '

  read choice

  case "$choice" in

   [0-9]) cd "$choice" ;;

    [Bb]) if [ ! `pwd` = "$root/maze" ]
          then
            cd ..
          else
            echo "Cannot go back, you are at the top of the maze."
          fi ;;

    [Qq]) exit 0 ;;

  esac
done