读取循环

时间:2016-05-10 15:21:36

标签: bash

我不确定我在这里缺少什么。我的程序中有以下读循环:

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

这会产生以下错误:

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

对于我的生活,我无法弄清楚错误是什么。 $startDate在前一个读取循环中定义,因此我知道不是$startDate未定义的事实。

我很欣赏第二组眼睛让我知道我在这些方面缺少什么。

1 个答案:

答案 0 :(得分:1)

您没有使用双分号终止上一个块。

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