Bash 转义macOS shell脚本上的空白
使用macOS内置的Bash 转义macOS shell脚本上的空白,bash,shell,escaping,rsync,Bash,Shell,Escaping,Rsync,使用macOS内置的rsyncversion(rsync版本2.6.9协议版本29)在macOS上运行以下脚本时,我遇到了一个问题 该脚本将一些文件和文件夹备份到我的dropbox中的特定文件夹,并由plist macOS启动守护程序在特定时间运行 #!/bin/bash # Halt the script on any errors. set -e target_path="/Users/alex/Dropbox/backup" # Create the target path if i
rsync
version(rsync版本2.6.9协议版本29)在macOS上运行以下脚本时,我遇到了一个问题
该脚本将一些文件和文件夹备份到我的dropbox中的特定文件夹,并由plist macOS启动守护程序在特定时间运行
#!/bin/bash
# Halt the script on any errors.
set -e
target_path="/Users/alex/Dropbox/backup"
# Create the target path if it doesn't exist.
mkdir -p "${target_path}"
# A list of absolute paths to backup.
things3="${HOME}/Library/Containers/com.culturedcode.ThingsMac/Data/Library/Application Support/Cultured Code/Things/Things.sqlite3"
include_paths=(
"${HOME}/.ssh"
"$things3"
# [...]
)
# A list of folder names and files to exclude.
exclude_paths=(
# [...]
)
# rsync allows you to exclude certain paths.
for item in "${exclude_paths[@]}"
do
exclude_flags="${exclude_flags} --exclude='"${item}"'"
done
# rsync allows you to pass in a list of paths to copy.
for item in "${include_paths[@]}"
do
include_args="${include_args} --include='"${item}"'"
done
# Finally, we just run rsync
rsync -avR --dry-run ${exclude_flags} ${include_args} ${target_path}
我面临以下错误,你知道为什么会出现这个问题吗
building file list ... rsync: link_stat "/Users/alex/Dropbox/bin/" failed: No such file or directory (2) rsync:
link_stat "/Users/alex/bin/ --include='/Users/alex/.ssh' --include='/Users/alex/Library/Containers/com.culturedcode.ThingsMac/Data/Library/Application Support/Cultured Code/Things/Things.sqlite3'" failed: No such file or directory (2) done
sent 29 bytes received 20 bytes 98.00 bytes/sec total size is 0 speedup is 0.00 rsync error: some files could not be transferred (code 23) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/rsync/rsync-52.200.1/rsync/main.c(996) [sender=2.6.9]
谢谢。对于
*\u标志
值也使用数组。添加到字符串中的引号不会转义空格;这些引号是数据的文字部分,而不是在参数展开后的shell语法
for item in "${exclude_paths[@]}"; do
exclude_flags+=(--exclude "$item")
done
for item in "${include_paths[@]}"; do
include_flags+=(--include "$item")
done
rsync -avR --dry-run "${exclude_flags[@]}" "${include_args[@]}" "${target_path}"
为什么要投否决票?