1 Replies - 732 Views - Last Post: 05 October 2013 - 08:45 AM Rate Topic: -----

#1 jrockfever  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-September 13

Windows Shell Script syntax error "This is a book example"

Posted 04 October 2013 - 02:47 PM

Hello, I have been trouble shooting a script from this ebook for one of my classes. Keep in mind this is the source code that was given out in the book. I am not asking for you to help me cheat, I just need to figure out why I keep receiving syntax errors from the authors original code. So that I am able to workout the editing of the original code.

Anyways, the book I am reading out of is "Microsoft Windows Shell script programming for the Absolute Beginner". Basically the code executes then once it reach's the final input from the user I receive a syntax error. The concept of the program is to take the users input. Once it finishes receiving the users input it should display a prompt called "score card" this just shows the total amount of questions, then the total correct and incorrect. At this point it takes the users input and stores it in a .txt file in the Temp folder in my local c:\ drive. While it executes this command it completely ignores the last step of the script to display the final verdict of answers in the windows shell console. It does store a .txt log of the program however it stops at question 7 and refuses to display the score card. This should be displayed right beneath the log of questions in the .txt file stored in the Temp folder that I have created in the c:\ drive.

Help is much appreciated thank you.

@ECHO off

REM ***************************************************************************
REM
REM Script Name: SixMillion.bat
REM Author: Jerry Ford
REM Date: July 12, 2003
REM
REM Description: This Windows shell script game tests the player's knowledge of
REM the 1970's Six-Million-Dollar Man TV show.
REM
REM ***************************************************************************

REM Script Initialization Section

REM Set the color scheme to yellow on black
COLOR 0E

REM Clear the display
CLS

REM Display the name of the game in the Windows command console's title bar
TITLE = THE   S I X  M I L L I O N  D O L L A R  Q U I Z

REM Define and initialize variables that will be used to track the total number
REM of right and wrong answers
SET /A Right = 0
SET /A Wrong = 0

REM Main Processing Section

REM Create a return point
:StartGame

REM Display the initial Welcome screen
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO              S I X  M I L L I O N  D O L L A R  Q U I Z
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO [Play] [Exit] [Help] [About]
ECHO.

REM Collect the player's response
SET /p reply= Option:

REM Determine what the player wants to do
IF /I "%reply%" == "" CLS & GOTO :StartGame

IF /I %reply% == Play CLS & GOTO :Play

IF /I %reply% == Exit CLS & GOTO :EOF
IF /I %reply% == Help CLS & GOTO :Help

IF /I %reply% == About CLS & GOTO :About


REM An incorrect response was provided, so redisplay the Welcome screen
CLS & GOTO :StartGame

REM Set up the Help screen
:HELP

ECHO.
ECHO.
ECHO.
ECHO                           HELP INSTRUCTIONS
ECHO.
ECHO In this game you will be presented with a series of questions
ECHO designed to test your knowledge of the Six-Million-Dollar Man TV series.
ECHO Some questions are "fill in the blank," some are True/False, and some are
ECHO Yes/No. Your score will be presented after you have answered all the
ECHO questions.
ECHO.
ECHO.
ECHO -------------------------------------------------------------------------
ECHO.
ECHO.
ECHO 1. Type Play and press Enter to begin the game.
ECHO.
ECHO 2. Type Exit and press Enter to stop playing the game.
ECHO.
ECHO 3. Type About and press Enter to learn more about the game and its author.
ECHO.
ECHO.
ECHO.

REM Pause to give the player time to read the screen
PAUSE

REM Clear the display
CLS

REM Return to the Welcome screen
GOTO :StartGame

REM Set up the About screen
:About

ECHO.
ECHO.
ECHO.
ECHO.
ECHO                   About The Six-Million-Dollar Quiz
ECHO.
ECHO                              Written by
ECHO.
ECHO                          Jerry Lee Ford, Jr.
ECHO.
ECHO.                      ------------------------
ECHO.
ECHO                             Copyright 2003
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Pause to give the player time to read the screen
PAUSE

REM Clear the display
CLS

REM Return to the Welcome screen
GOTO :StartGame

REM Begin the play of the game
:Play

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest1= 1. What was the Six-Million-Dollar Man's first name?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest2= 2. Did he have 1 or 2 bionic arms?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest3= 3. Did he have a bionic eye or bionic ear?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest4= 4. What was his real last name?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest5= 5. What was the first name of the Six-Million-Dollar Man's real wife?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest6= 6. What was the last name of the actress who played the bionic woman?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest7= 7. Did the bionic woman have a bionic eye or bionic ear?

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest8= 8. T/F: The bionic woman cost more than the Six-Million-Dollar Man.

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest9= 9. T/F: The Six-Million-Dollar Man was known as Heath on the "Big Valley."

REM Clear the display
CLS

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Ask a question
SET /p quest10= 10. Yes/No: Did the Six-Million-Dollar Man ever marry the Bionic woman?

REM Clear the display
CLS

REM If the C:\TEMP folder does not exist, then create it
IF NOT EXIST C:\TEMP\. (
  MKDIR C:\Scripts
)

REM Create the Quiz.txt file if it does not exist. Overwrite it if it does exist
ECHO. > C:\TEMP\Quiz.txt

REM Begin appending game results to the report
ECHO The Six-Million-Dollar-Man Quiz Score Card Report >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt

REM Determine whether the right or wrong answer was given and append the
REM the appropriate text for each of the ten questions
IF /I %quest1% == Steve (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 1. What was the Six-Million-Dollar Man's first name? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Steve - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 1. What was the Six-Million-Dollar Man's first name? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest1% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest2% == 1 (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 2. Did he have 1 or 2 bionic arms? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: 1 - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 2. Did he have 1 or 2 bionic arms? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest2% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest3% == Eye (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 3. Did he have a bionic eye or bionic ear? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Eye - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 3. Did he have a bionic eye or bionic ear? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest3% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest4% == Majors (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 4. What was his real last name? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Majors - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 4. What was his real last name? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest4% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest5% == Farrah (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 5. What was the first name of the Six-Million-Dollar Man's real wife? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Farrah - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 5. What was the first name of the Six-Million-Dollar Man's real wife? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest5% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest6% == Wagner (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 6. What was the last name of the actress who played the bionic woman? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Wagner - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 6. What was the last name of the actress who played the bionic woman? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest6% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest7% == Ear (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 7. Did the bionic woman have a bionic eye or bionic ear? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Ear - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 7. Did the bionic woman have a bionic eye or bionic ear? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest7% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest8% == F (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 8. True/False: The bionic woman cost more than the Six-Million-Dollar Man. >>
C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: False - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 8. True/False: The bionic woman cost more than the Six-Million-Dollar Man. >>
C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest8% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest9% == T (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 9. True/False: The Six-Million-Dollar Man was known as Heath on the "Big Valley." >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: True - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 9. True/False: The Six-Million-Dollar Man was known as Heath on the "Big Valley." >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest9% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

IF /I %quest10% == Yes (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 10. Yes/No: Did the Six-Million-Dollar Man ever marry the Bionic woman? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: Yes - Correct! >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A right += 1
) ELSE (
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO 10. Yes/No: Did the Six-Million-Dollar Man ever marry the Bionic woman? >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  ECHO    Your answer was: %quest10% - Incorrect. >> C:\TEMP\Quiz.txt
  ECHO. >> C:\TEMP\Quiz.txt
  SET /A wrong += 1
)

REM Append a few blanks lines and then append score card data
ECHO. >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO ------------------------------------------------------------------------------------ >>
C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO Score Card: >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO.>> C:\TEMP\Quiz.txt
ECHO Total number of questions on the quiz          = 10 >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO Total number of correctly answered questions   = %right% >> C:\TEMP\Quiz.txt
ECHO. >> C:\TEMP\Quiz.txt
ECHO Total number of incorrectly answered questions = %wrong% >> C:\TEMP\Quiz.txt

REM Clear the display
CLS

REM Display score card data in the Windows command console and inform the player
REM about the availability of the Games.txt file
ECHO.
ECHO.
ECHO.
ECHO                      Six-Million-Dollar-Man Score Card
ECHO.
ECHO.
ECHO -------------------------------------------------------------------------------
ECHO.
ECHO Total number of questions on the quiz           = 10
ECHO.
ECHO Total number of correctly answered questions    = %right%
ECHO.
ECHO Total number of incorrectly answered questions  = %wrong%
ECHO.
ECHO -------------------------------------------------------------------------------
ECHO.
ECHO.
ECHO A detailed score card report can be found at C:\TEMP\Quiz.txt
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.

REM Terminate the script's execution
GOTO :EOF



Is This A Good Question/Topic? 0
  • +

Replies To: Windows Shell Script syntax error "This is a book example"

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1335
  • View blog
  • Posts: 4,574
  • Joined: 19-February 09

Re: Windows Shell Script syntax error "This is a book example"

Posted 05 October 2013 - 08:45 AM

Hi, it looks as if you have a couple of lines where the filename has been put on the next line by mistake.

401	  ECHO 8. True/False: The bionic woman cost more than the Six-Million-Dollar Man. >>
402	C:\TEMP\Quiz.txt
...
409	  ECHO 8. True/False: The bionic woman cost more than the Six-Million-Dollar Man. >>
410	C:\TEMP\Quiz.txt


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1