语法错误:“(”意外(期望“然后”)

Ton*_*taz 7 ssh bash if-statement syntax-error while-loop

我在使用 bash 脚本时遇到了麻烦。我正在尝试通过 ssh 自动化将文件发送到我的树莓派的过程。我想提示输入文件/目录的路径,然后将其复制到/home/pi/push我的 pi 上的目录中。然后我想问一下是否还有另一个文件要发送,如果是,则再次循环,否则退出程序。出于明显的安全原因,我将 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
Run Code Online (Sandbox Code Playgroud)

如果您对实现这一目标的更好方法有任何建议,那也太棒了!

mik*_*n32 0

只需or在测试中使用 an ,或在正则表达式中转义括号即可。另外,不需要用nocasematchset 来测试 case;有了这个要求,您甚至不需要正则表达式。

shopt -s nocasematch
...
if [[ "$response" = "yes" || "$response" = "y" ]]
Run Code Online (Sandbox Code Playgroud)