I'm working on my dotfiles scripts, and am creating a restore.sh
script to copy preferences, folders, etc. after a clean install.
I've created a check to see if a drive name was entered as an argument, and if not to use a default drive. But!... the default drive has spaces in the filename.
So I've created a test script to copy a file from /Users/tim/My Folder/file.txt
to ~/Desktop/file.txt
if [[ $# -eq 0 ]];
then
dir="My\ Folder"
else
dir=$1
fi
options=(-a -v -h -W --progress --compress-level=0)
rsync "${options[@]}" "/Users/tim/$dir/file.txt" "~/Desktop/file.txt"
That doesn't work, so I've been playing with variations on this
from="/Users/tim/$dir/file.txt"
to="~/Desktop/file.txt"
options=(-a -v -h -W --progress --compress-level=0 $from $to)
rsync "${options[@]}"
But I continually get the following error
rsync: link_stat "/Users/tim/My\ Folder/file.txt" failed: No such file or directory (2)
I've been reading up on this and thought arrays were the way to add spaces in variables, but so far nothing I'm trying is working.