Syntax error: "(" unexpected (expecting "then")

Syntax error: "(" unexpected (expecting "then")

我在使用 bash 脚本时遇到问题。我正在尝试通过 ssh 自动执行将文件发送到我的 raspberry pi 的过程。我想提示输入 file/directory 的路径,然后将其复制到我的 pi 上的 /home/pi/push 目录。然后我想询问是否还有另一个文件要发送,如果是则再次循环,否则退出程序。出于明显的安全原因,我将 IP 地址清零。

done=0
while [ $done -lt 1 ]
do
    read -r -p "Path to file: " path
    spawn scp -r $path pi@000.00.000.00:/home/pi/push
    expect "assword:"
    send "password\r"
    interact

    read -r -p "Send another? [y/N] " response
    if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
    then
        $done=1
    else
        echo "Ending file transfer."
    fi
done

如果您对实现此目标的更好方法有建议,那就太好了!

只需在测试中使用一个or,或者在正则表达式中转义括号。此外,无需测试设置 nocasematch 的情况;有了这个要求,您甚至不需要正则表达式。

shopt -s nocasematch
...
if [[ "$response" = "yes" || "$response" = "y" ]]