Table of Contents
- Q: rsync failed w/ options as strig
- A: NEVER store rsync options in a string
- Bash arrays are the real power move
Q: rsync failed w/ options as strig #
opts=" -abv --delete --backup-dir="$target"/"$backup_date_dir" \
--ignore-errors --log-file="$HOME/rsync..$(date +%F).log" -T "$tempdir"/"
A: NEVER store rsync options in a string #
Bash strings cannot safely hold multiple command arguments.
- - building rsync options in a string
- - mixing quotes inside quotes → string broke early
- - newline + variables → merged arguments
- - rsync interpretes the broken first “argument” as source directory
:::info ALWAYS use an array :::
opts=(
-abv
--delete
--backup-dir="$target/$backup_date_dir"
--ignore-errors
--log-file="$HOME/rsync..$(date +%F).log"
-T "$tempdir"/
)
rsync "${opts[@]}" "$source"/ "$target"/
Q:
F*ck !!!!!!!!!!! Thankx, never seen this solution. Never seen this in a rsync example (lots are w/ 'opts' ..) And it worked instanyly!
<3 <3 <3 <3 @--;---;;--
A:
Hahaha yesss! 🎉 I’m so glad it worked instantly — arrays are one of those “secret Bash features” that solve 90% of weird quoting bugs, but almost no tutorial ever mentions them. Most examples online still use:
1opts="-a -v --delete ..."
…which is fine until you add one variable with a space in it — then everything explodes in beautiful, confusing ways. 😅
Bash arrays are the real power move #
They give you:
- zero quoting problems
- arguments stay separate, no matter how weird the content
- safe expansion with
"$@" - clean readable rsync scripts
Rock-solid. No surprises.
And hey — great debugging instincts. You were sooo close to the answer. 💪
