Linux Bash Shell脚本-p不是有效的标识符

时间:2016-02-15 15:28:51

标签: linux bash shell

我正在创建一个程序,该程序应该将用户输入与文件中的字符串进行比较。

输入:./script Questions.txt Answers.txt

这是我的计划:

#!/bin/bash
declare -a existing_answ
i=0
j=0
Number_of_correct_answers=0
Number_of_wrong_answers=0
while IFS='' read -r line || [[ -n "$line" ]]
do
    existing_answ[$i]="$line"
    let "i=i+1"
done < "$2"

while IFS='' read -r line || [[ -n "$line" ]]
do
    echo "$line"
    while [ -z "$arg1" ]
    do
            read –p "Your answer: " arg1
    done


    if [[ ${existing_answ[$j]} == "$arg1" ]]
    then
            let "Number_of_correct_answers++"
    else
            let "Number_of_wrong_answers++"
    fi
    let "j=j+1"
done < "$1"
echo "$Number_of_correct_answers"
echo "$Number_of_wrong_answers"

什么是无限循环说-p is not a valid identifier 用户输入的相同脚本在我以前的程序中工作,这里没有。 我错过了什么或者它有什么问题吗?

1 个答案:

答案 0 :(得分:4)

问题在于,\n', '\t\t\t\t\t\t\t\t\t\tTEXT_I_WANT\t\t\t\t\t\t\t\t\t 中的字符不是-p中的ASCII连字符,而是p之前的字符是typographic en-dash。你应该用普通的ASCII连字符替换它。