语法错误:意外的文件结尾 - Bash 脚本

语法错误:意外的文件结尾 - Bash 脚本

我正在尝试创建一个 spritz 应用程序!一切都运行良好,但从昨天开始,我一直收到此错误:./spritz:第 176 行:语法错误:文件意外结束

我检查了脚本文件,一切看起来都很完美!我很困惑我终于有了一个 if 语句,它看起来是正确的!这是最后一部分:

    #checks if speed is 150
157 if [[ $2 -eq 150 ]];
158 then
159 starttime=$SECONDS
160      FS=$'\n'
161      for j in `grep --color=always -iP '\b[^aeiou\s]*[aeiou][^aeiou\s]*\K[aeiou]' $1`;
162      do
163            #Reads the text file in the centre of the screen
164            echo "                                                    ___________________"
165            echo "                                                             $j";
166            echo "                                                    ___________________"
167            echo "                                                                               Speed 150 wpm"
168            sleep  0.9;
169            clear;
170       done
171 endtime=$(($SECONDS - $starttime))
172            echo "You read $words_read words in $endtime seconds!"
173       exit 8
174 fi

答案1

我更正了一些陈述,删除了一些;并再次格式化。这是工作结果:

#checks if speed is 150
if [ $2 -eq 150 ] ; then
    words=0
    starttime=$(date +%s)
    FS=$'\n'
    for j in $(grep --color=always -iP '\b[^aeiou\s]*[aeiou][^aeiou\s]*\K[aeiou]' $1) ; do
        #Reads the text file in the centre of the screen
        echo "                                                    ___________________"
        echo "                                                             $j";
        echo "                                                    ___________________"
        echo "                                                          Speed 150 wpm"
        sleep  0.9
        clear
        words=$(( $words + 1 ))
    done

    endtime=$(( $(date +%s) - $starttime ))
    echo "You read $words words in $endtime seconds!"

    exit 8
fi

相关内容