巴什 - 文件名Rsync的变量空间 [英] Bash -- Rsync variable in filename has spaces
问题描述
一直在寻找小时,仍然无法想出解决办法:(
Been searching for hours and still cant figure this out :(
不管怎样,即时创建一个脚本,该脚本会自动rsync的另一台服务器上约40个不同的目录,其他40目录。如果你想看到整个脚本,你可以在这里查看: http://pastebin.com/Nt3KKvx9
Anyway, im creating a script that will automatically rsync about 40 different directories to 40 other directories on another server. if you want to see the entire script you can view it here: http://pastebin.com/Nt3KKvx9
但重要的一点是对循环,我运行的rsync
But the important bit is the for loop where i run rsync
for ((i=0; i<${#websys[@]}; i++))
do
localpath="/nusdata/staff/NUS/NUS/Systems/${kiskasys[$i]}"
remotepath="/home/www/html/nusalaska.com/html/systems/${websys[$i]}"
rsync -rlptnvz -s "$localpath" -e "ssh -p 50014" "nusak@webserver:$remotepath/"
done
问题是,在数组kiskasys具有空间在他们许多目录名称(例如:'101 greenbrook')。
我试图使数组变量有他们周围的单引号,他们周围双引号,像逃跑'\\'的空间,三个人的组合。我也曾尝试把$的localPath在引号,不加引号,等等等等。
The problem is that the array "kiskasys" has many directory names that have spaces in them (Example: '101 greenbrook'). I have tried making the array variables have single quotes around them, double quotes around them, escaped spaces like '\ ', and combinations of all three. I have also tried putting the $localpath in quotes, not in quotes, etc. etc.
我猜IM的-s(--protect-参数)如何与空间交易和我怎样才能得到它在我的处境工作只是困惑。
I guess im just confused on how the -s (--protect-args) deals with the spaces and how I can get it to work in my situation.
错误输出总是看起来像下面这样:
The error output always looks something like the following:
rsync: change_dir "/nusdata/staff/NUS/NUS/101" failed: No such file or directory (2)
或
rsync: change_dir "/nusdata/staff/NUS/NUS/'101 greenbrook'" failed: No such file or directory (2)
任何帮助AP preciated!
Any help is appreciated!
感谢
在从我的脚本复制我的code到这个网页我不小心抄错了......但在抄袭是错误的,我上面贴了非常好的code工作正常哈哈。
In copying my code from my script to this page I accidently copied it wrong... however in copying it wrong, what i posted above was perfectly good code that works fine haha.
所以,我上面贴的是解决我自己的问题。
so what i posted above was the solution to my own problem.
原来曾在可变局部路径单引号,像这样:
The original had single quotes in the localpath variable like so:
localpath="'/nusdata/staff/NUS/NUS/Systems/${kiskasys[$i]}'"
和单引号是问题。而对于这里的每个人的利益是一个例子输出
and the single quotes was the problem. And for everyone's benefit here is an example output
echo ${kiskasys[1]}
#output would look like this:
101 greenbrook
基本上没有特殊的转义字符等。
Basically there are no special escape characters etc.
推荐答案
有关它的价值,我不能复制您的问题。如果我设置的localPath
和 remotepath
与空格的目录:
For what it's worth, I'm not able to replicate your problem. If I set localpath
and remotepath
to a directory with spaces:
localpath="/home/lars/tmp/so/dir1/a directory"
remotepath="/home/lars/tmp/so/dir2/a directory"
然后运行你的的rsync
命令(我的环境略有修改):
And then run your rsync
command (modified slightly for my environment):
rsync -rlptvz -s "$localpath/" -e "ssh" "localhost:$remotepath/"
这只是工作。这里的内容 DIR1
:
dir1/a directory/file1
dir1/a directory/file3
dir1/a directory/file2
和rsync的运行后, DIR2
是这样的:
And after running rsync, dir2
looks like this:
dir2/a directory/file1
dir2/a directory/file3
dir2/a directory/file2
您可以显示的具体的导致在你上面看到的错误命令行?也许运行与 -x
标记的脚本,并显示究竟是如何的localPath
和 remotepath
设置。
Can you show a specific command line that results in the errors you're seeing above? Maybe run the script with the -x
flag and show exactly how localpath
and remotepath
are set.
这篇关于巴什 - 文件名Rsync的变量空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!