Reputation: 537
I'm trying to write a backup script that takes a directory and directory/file name as arguments to the script. The problem is curating the target directory of the backups. For safety, I'm currently moving the files into MacOS ~/.Trash/
. The problem is that I want to support having spaces in the target directory's file name, but escaping the path in mv
prevents shell expansion of *
.
The script in question:
# Usage: backup-to-dropbox.sh "path/containing/target" "target dir"
cd "$1"
DATE=`date "+%Y%m%dT%H%M%S"`
SOURCE="$2"
mv "~/Dropbox/Backups/$SOURCE*.tgz" ~/.Trash/ ## Problem line here
tar -czf "$SOURCE $DATE.tgz" "$SOURCE/"
mv "$SOURCE $DATE.tgz" ~/Dropbox/Backups/
How can I match all the files with this known, arbitrary prefix and fixed extension?
Upvotes: 1
Views: 1462
Reputation: 385670
Words can be partially quoted. Be sure not to quote anything expanded by the shell.
mv ~/"Dropbox/Backups/$SOURCE"*.tgz ~/.Trash/
Upvotes: 1