bash rsync 找不到带空格的目录
bash rsync can't find directory with spaces
我正在尝试制作一个备份脚本,但问题是它找不到包含 space 的目录。
bash 脚本的代码。
#!/bin/bash
Desk="/Users/elev/Desktop/"
include_paths=(
"${Desk}/Skola"
"${Desk}/music"
"${Desk}/jobb"
# not working directory
"${Desk}/programmering\ skola"
)
# ${include_paths[@]} means every value in the list
for item in "${include_paths[@]}"
do
include_args="${include_args} ${item}"
done
DestPath="/Volumes/Atheer/backup"
rsync -av --delete ${include_args} $DestPath
如您所见,我已尝试使用反斜杠和 space,但仍然无效。我收到以下错误代码 rsync: link_stat "/Users/elev/Desktop/programmering\" failed: No such file or directory 我希望它也能备份包含 space 的目录。感谢您的帮助
您已经知道如何使用数组。你应该更多地使用它们。 :)
rsync -av --delete "${include_paths[@]}" "$DestPath"
"${include_paths[@]}"
(引号必不可少!)将 include_paths
数组中的每个元素扩展为单独的 rsync
参数。
根本没有理由生成 include_args
。
这是另一个错误:
"${Desk}/programmering\ skola"
尝试
"${Desk}/programmering skola"
从 man bash
中提取双引号:
The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or newline.