dimanche 16 décembre 2018

Scripts with Conditionals - Line 37 error?

So this is my bash script, The point of the script is to go through a story and allow you to do options to affect the outcome. Sadly, the code can easily tell you this but I have to type this much jazz so I can even post this on StackOverflow.

#!/bin/bash
echo “Once upon a time, there was a secret castle out in the woods. You were riding on your horse when you noticed the large structure. There was a wall around the entirety of the castle. You think to yourself that there may be an entrance somewhere. You could also just climb and hop over the wall. Do you look or do you climb?”
#pauses for 10 seconds using the sleep command 
sleep 10
#reads the user input to the prompt, sets it to ANSWER
read ANSWER
#creates if statement where user input determines the path the story will take
if [“$ANSWER” = “look” ]; then
#if the response from the user was “look,” then the look prompt is echoed 
    echo “You keep looking but you cannot find an entrance through the wall. Do you go home or do you hop wall?”
#the sleep command pauses the script so the user has time to read the echo
    sleep 10
#their answer to the prompt is set to ANSWER2
read ANSWER2
#another if statement is used to give the user another prompt depending on their answer
if [“$ANSWER2” = “hop wall”]; then
# if the answer was “hop wall,” the hop wall prompt is echoed 
echo “You climb over the wall. It is a little moist from tree sap but you do not mind. Now you are in the court of the castle. You see the entrance to the actual castle a few hundred feet away. Do you walk over or do you keep looking?”
#the sleep command is used, the script pauses for 10 second 
sleep 10
#the user response is stored as ANSWER3
read ANSWER3
#another if statement is used to determine what prompt to echo to user
if [“$ANSWER3” = “walk over”]; then
#if the user responded with “walk over” the the walk over prompt is given
echo “You walk over to the entrance. Except it is not an entrance. It is a trap. Guards see you and they rush and capture you. Now you must live in a dungeon for eternity. The end.”
#an exit code is used to end script. Code successful.
Fi 
exit 0
#if the answer from ANSWER3 was “keep looking, a different prompt is given with the help of an else if statement
else if [“ANSWER3” = “keep looking”]; then
# “keep looking” prompt is echoed 
    echo “You keep looking and eventually you notice a someone else who seemingly hopped the wall. There are a few guards that yell that he does not belong here and that he will now die so that he cannot expose the castle to the public. He is thrown into a pit of flames. You realize coming here was a big mistake. You climb the wall before anyone notices and escape with your life. What a day, you thought. The end.”
#exit code 0 is used to exit the script. Code successful
exit 0

#if the response ANSWER2 is “go home,” an if statement helps further the story with that option choice
else if[“$ANSWER2” = “go home”]; then
# “go home” prompt is echoed to user
    echo “You decide to hop on your horse and head home. That is all. The end.”
#exit code 0 is used to exit script. Code successful.
exit 0
# if the first answer given by the user is “climb” the else if statement handles that case
else if [ "$ANSWER" = “climb” ]; then
#the climb prompt is echoed 
echo “You climb over the wall. It is a little moist from tree sap but you do not mind. Now you are in the court of the castle. You see the entrance to the actual castle a few hundred feet away. Do you walk over or do you keep looking?”
#the script pauses for 10 seconds with the sleep command
sleep 10
#the user input is read and stored as ANSWER3 
read ANSWER3
#an if statement helps further the path of the story, in this case, if the answer was “walk over”
if [“$ANSWER3” = “walk over”]; then
#the walk over prompt is echoed
echo “You walk over to the entrance. Except it is not an entrance. It is a trap. Guards see you and they rush and capture you. Now you must live in a dungeon for eternity. The end.”
#an exit code exits the script. Code successful.
exit 0
#an else if statement is used for the case where the input was “keep looking”
else if [“ANSWER3” = “keep looking”]; then
#if the ANSWER3 is “keep looking” the keep looking prompt is echoed
    echo “You keep looking and eventually you notice a someone else who seemingly hopped the wall. There are a few guards that yell that he does not belong here and that he will now die so that he cannot expose the castle to the public. He is thrown into a pit of flames. You realize coming here was a big mistake. You climb the wall before anyone notices and escape with your life. What a day, you thought. The end.”
# exit code 0 is used to exit script. Code successful.
exit 0
#an else if statement handles the alternate answer for ANSWER2
else if[“$ANSWER2” = “go home”]; then
# if ANSWER2 is “go home” the go home prompt is echoed 
    echo “You decide to hop on your horse and head home. That is all. The end.”
# exit code 0 is used to exit script. Code successful.
exit 0

I'm not entirely sure why this is working, I'm just trying to figure out whats going on. (I suck at this)

When I run my script, this is what I get -

./Lab4p2: line 39: syntax error near unexpected token `then'
./Lab4p2: line 39: `elif[“$ANSWER2” = “go home”]; then'

I'd appreciate all and any help

Aucun commentaire:

Enregistrer un commentaire