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

标签 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"

什么是 get 是一个无限循环说 -p 不是一个有效的标识符 用于用户输入的相同脚本在我以前的程序中起作用,但在这里不起作用。 我是不是漏掉了什么或者有什么问题?

最佳答案

问题是 -p 中的 ASCII 连字符减号字符,p 之前的字符是 typographic en-dash .您应该将其替换为常规的 ASCII 连字符减号。

关于Linux Bash Shell 脚本 -p 不是有效标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35413114/

相关文章:

php - 使用 php 从给定的 url 下载 apk 文件到服务器

linux - 隐藏 ps 中的命令执行检测

linux - 无法删除 SAMBA 中的用户

bash - 在 shell 脚本中减去字符串(即数字)

linux - 尝试回显字符串值而不是 $string

python - 模块未找到错误 : No module named 'pandas' - when I have pandas already installed

linux - Bash:遍历文件并读取子字符串作为参数,执行多个实例

regex - 两个不同文件的 Bash grep 正则表达式问题

xml - 在 bash 脚本中提取 XML 值

php - 无法使用 PHP 运行 shell 脚本文件