我在使用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 [email protected]:/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
set情况;有了这个要求,您甚至不需要正则表达式。
shopt -s nocasematch
...
if [[ "$response" = "yes" || "$response" = "y" ]]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句