0

I'm not sure what I'm missing here. I've got the following read loop in my program:

while true
do
    read -p "Would you like to enter an end date (y/n) (if no, end date will default to today) " answer

    case $answer in
    [yY]* ) while true
            do
                read -p "Please enter an end date in yyyymmdd format: " answer

                echo Running script from dates  $startDate  to  $answer
                ruby $DIR/dinersDataAutomation.rb -s $startDate -e $answer
                break
            done
            break

    [nN]* ) echo Running script with a start date of  $startDate
            ruby $DIR/dinersDataAutomation.rb -s $startDate
            break

    * )     echo "Please enter Y or N"
    esac
done

This produces the following error:

./getDinersInfo.sh: line 56: syntax error near unexpected token `)'
./getDinersInfo.sh: line 56: `      [nN]* ) echo Running script with a start date of  $startDate'

For the life of me I can't figure out what the error could be. $startDate gets defined in a previous read loop, so I know it's not the fact that $startDate isn't defined.

I'd appreciate a second set of eyes to let me know what I'm missing on these lines.

0

1 Answer 1

1

You didn't terminate the previous block with a double semicolon.

case $answer in
    [yY]* ) while true
            do
                read -p "Please enter an end date in yyyymmdd format: " answer

                echo Running script from dates  $startDate  to  $answer
                ruby $DIR/dinersDataAutomation.rb -s $startDate -e $answer
                break
            done
            break
            ;;

    [nN]* ) echo Running script with a start date of  $startDate
            ruby $DIR/dinersDataAutomation.rb -s $startDate
            break
            ;;

    * )     echo "Please enter Y or N"
            ;;
esac
Sign up to request clarification or add additional context in comments.

4 Comments

Also, what is the point of while true; do ...; break; done? ... would have the same effect with a lot less noise.
I debated whether or not to address that; it's probably a semantic error (not testing the value of answer before breaking out of the loop), but it's not a syntax error.
Possibly, but you removed the break statements from the outer while loop, which makes it infinite instead of repeating only in the *) case. (Those break statements were not (just) to break out of case.) When I first looked at the Q, I thought that OP believed that you could only use read in a while loop, but now I'm tending towards thinking that it's a slightly warped style.
Ah, right, I didn't pay enough attention to the outer loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.