简体   繁体   English

bash 脚本使用 rsync 复制目录名中带有空格的目录时出错

[英]error with bash script using rsync to copy directory with space in directory name

I've been trying all morning to get this to work, but can't find a fix.我整个上午都在努力让它工作,但找不到解决办法。 I'm trying to make a bash script rsync backup a copy of a directory.我正在尝试制作 bash 脚本 rsync 备份目录的副本。 I keep running into a problems linked to species in the directory name.我一直遇到与目录名称中的物种相关的问题。 I can't seem to apply or find any previous fix to get this to work.我似乎无法应用或找到任何以前的修复程序来使其正常工作。 Any help would be greatly appreciated.任何帮助将不胜感激。 Raj (Newbie)拉吉(新手)

I think the issue is getting the space in the directory name "Application Support" to be accepted by the script.我认为问题在于让脚本接受目录名称“Application Support”中的空间。

Thank you in advance.先感谢您。

Here's the bash script:这是 bash 脚本:

!/bin/bash

backuptodirectory=/Volumes/Backup/date/
directorytocopy=/Users/myname/Library/Application Support

if [ ! -d "$directorytocopy" ]; then
    echo "Source path: $directorytocopy doesn't exist"
    exit 1
fi
mkdir -p "$backuptodirectory"
echo copying $directorytocopy
rsync -progress $directorytocopy $backuptodirectory

For future reference, this is the changed script (which now works).为了将来参考,这是更改后的脚本(现在可以使用)。 Thank you Aserre.谢谢阿塞尔。

!/bin/bash

backuptodirectory=/Volumes/Backup/date/
directorytocopy=/Users/myname/Library/Application\ Support

if [ ! -d "$directorytocopy" ]; then
    echo "Source path: $directorytocopy doesn't exist"
    exit 1
fi
mkdir -p "$backuptodirectory"
echo copying $directorytocopy
rsync -progress "$directorytocopy" "$backuptodirectory"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM