Bash 从文件中读取rsync源会导致使用空格对文件名进行不正确的解析

Bash 从文件中读取rsync源会导致使用空格对文件名进行不正确的解析,bash,shell,unix,scripting,rsync,Bash,Shell,Unix,Scripting,Rsync,我编写了一个简单的脚本,搜索由变量“SCOPE”定义的特定目录,生成一个目录列表,这些目录在过去24小时内被修改,并打印到临时文件中。删除文件的第一行(以排除目录的根级别)。最后,它将临时文件和rsync的每个目录的内容循环到目标 问题 名称中包含空格的目录不进行rsync。空格导致空格前和空格后的所有内容都作为单个参数传递,因此文件名无效 观察当我检查临时文件的内容时,每个目录按预期显示在一行上。似乎只有当它从文件读入rsync时 如何防止目录名中的空格阻止这些目录无法rsync SCOPE=

我编写了一个简单的脚本,搜索由变量“SCOPE”定义的特定目录,生成一个目录列表,这些目录在过去24小时内被修改,并打印到临时文件中。删除文件的第一行(以排除目录的根级别)。最后,它将临时文件和rsync的每个目录的内容循环到目标

问题 名称中包含空格的目录不进行rsync。空格导致空格前和空格后的所有内容都作为单个参数传递,因此文件名无效

观察当我检查临时文件的内容时,每个目录按预期显示在一行上。似乎只有当它从文件读入rsync时

如何防止目录名中的空格阻止这些目录无法rsync

SCOPE="/base/directory"           
DESTINATION="/volumes/destination/"       

find "$SCOPE" -maxdepth 1 -type d -mtime 0 > /tmp/jobs.txt;

sed '1d' /tmp/jobs.txt > /tmp/tmpjobs.txt;                      
mv /tmp/tmpjobs.txt /tmp/jobs.txt;

for JOB in `cat /tmp/jobs.txt`; do
    rsync -avvuh "$JOB" "$DESTINATION";          
done

rsync端需要
-0
选项,find端需要
-print0
选项。有许多实用程序对此有一些变化,因此这是一个简单的解决方案

从Linux上的查找(1)手册页:

   -print0
          True; print the full file name on the standard output, followed by a null  character  (instead
          of  the  newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find  out-
          put.  This option corresponds to the -0 option of xargs.

rsync端需要
-0
选项,find端需要
-print0
选项。有许多实用程序对此有一些变化,因此这是一个简单的解决方案

从Linux上的查找(1)手册页:

   -print0
          True; print the full file name on the standard output, followed by a null  character  (instead
          of  the  newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find  out-
          put.  This option corresponds to the -0 option of xargs.

rsync端需要
-0
选项,find端需要
-print0
选项。有许多实用程序对此有一些变化,因此这是一个简单的解决方案

从Linux上的查找(1)手册页:

   -print0
          True; print the full file name on the standard output, followed by a null  character  (instead
          of  the  newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find  out-
          put.  This option corresponds to the -0 option of xargs.

rsync端需要
-0
选项,find端需要
-print0
选项。有许多实用程序对此有一些变化,因此这是一个简单的解决方案

从Linux上的查找(1)手册页:

   -print0
          True; print the full file name on the standard output, followed by a null  character  (instead
          of  the  newline character that -print uses).  This allows file names that contain newlines or
          other types of white space to be correctly interpreted by programs that process the find  out-
          put.  This option corresponds to the -0 option of xargs.
替换

for JOB in `cat /tmp/jobs.txt`; do
    rsync -avvuh "$JOB" "$DESTINATION";          
done

读取-r作业时的
;做
rsync-avvuh“$JOB”“$DESTINATION”
完成
更换

for JOB in `cat /tmp/jobs.txt`; do
    rsync -avvuh "$JOB" "$DESTINATION";          
done

读取-r作业时的
;做
rsync-avvuh“$JOB”“$DESTINATION”
完成
更换

for JOB in `cat /tmp/jobs.txt`; do
    rsync -avvuh "$JOB" "$DESTINATION";          
done

读取-r作业时的
;做
rsync-avvuh“$JOB”“$DESTINATION”
完成
更换

for JOB in `cat /tmp/jobs.txt`; do
    rsync -avvuh "$JOB" "$DESTINATION";          
done

读取-r作业时的
;做
rsync-avvuh“$JOB”“$DESTINATION”
完成
如果不需要tmp文件,也可以使用“一行”命令:


如果不需要tmp文件,也可以使用“一行”命令:


如果不需要tmp文件,也可以使用“一行”命令:


如果不需要tmp文件,也可以使用“一行”命令:


这就成功了。参数现在已正确处理,结果与预期一致。谢谢,这很好。参数现在已正确处理,结果与预期一致。谢谢,这很好。参数现在已正确处理,结果与预期一致。谢谢,这很好。参数现在已正确处理,结果与预期一致。谢谢,很好的提示,谢谢。这是更有效和可读性。伟大的提示,谢谢。这是更有效和可读性。伟大的提示,谢谢。这是更有效和可读性。伟大的提示,谢谢。这是更有效和可读性。