rsync脚本错误地扩展变量

时间:2015-07-02 08:29:09

标签: bash scripting rsync file-processing

我有一个脚本,它从文件中获取唯一的位置编号。例如,这些格式如7325-05,5269-09和7479-14。前四个数字是文件夹的名称,第二个数字是每个文件夹中唯一的文件名前两个字符。

所以我编写了这个脚本来使用locate和find来获取文件夹的完整路径,然后使用通配符使用rsync下载特定文件。这是我现在的剧本:

#!/bin/bash

#IFS='
#'
oIFS=$IFS
IFS=$'\n'

while read line;
do
    name=$line;
    folder=${line:0:4}
    track=${line: -2}
    folderlocation="$(locate -r '/'$folder'$')"
    filelocation="$(find "$folderlocation" -type f -name "$track*")"
    rsync -vazhn --progress "$filelocation" /cygdrive/c/
#    mkdir /cygdrive/c/test/"$folder"
#    cp -rvi "$filelocation" /cygdrive/c/test/"$folder"

    echo "";
done < $1

使用被注释掉的cp的代码工作得很好。我真的更喜欢使用rsync,主要是因为我可以告诉你更好的反馈和更准确的进度报告。

使用上面粘贴的代码(使用rsync)会抛出此错误:

./filelocator classic-locations.txt
sending incremental file list
rsync: change_dir "/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/7001-8000/7201-7300/7252/Unknown Album (29-12-2012 09-52-02)" failed: No such file or directory (2)

sent 20 bytes  received 12 bytes  64.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

sending incremental file list
rsync: change_dir "/home/emil//\\sandrew-nas/SMMUSIC/MMIMUSIC/7001-8000/7201-7300/7252/Unknown Album (29-12-2012 09-52-02)" failed: No such file or directory (2)

sent 20 bytes  received 12 bytes  64.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1165) [sender=3.1.1]

正如您所看到的,我的主文件夹(我发出命令的地方)突然包含在脚本中,这使我相信在本地shell中扩展了变量或通配符,但似乎没有任何转义字符数量用rsync完成我想要的东西。

0 个答案:

没有答案