I have this issue with borgbackup, but because the reaction is the same, I will use rsync
in my example.
I want to build an array of arguments by adding a prefix to each, and then give that array to rsync
. But rsync
acts like it doesn't exist.
With this script:
#!/usr/bin/env bash
#
declare -a exclude_String
for excludestr in $(cat ./list); do
exclude_String+=(--exclude=$excludestr)
done
rsync "${exclude_String[@]}" . $Destination
and ./list
:
'/home/*'
'*.vim*'
A ps
of the process running does shows the argument correctly:
/usr/bin/rsync --exclude='*.vim*' --exclude='/home/*' . DESTINATION
But rsync
still acts like they aren't there. I found this question on the subject, so I tried:
#!/usr/bin/env bash
#
declare -a exclude_String
exclude_String+=(--exclude='/home/*')
exclude_String+=(--exclude='*.vim*')
rsync "${exclude_String[@]}" . $Destination
And this actually worked.
I don't understand much yet about shell expansion and stuff, I've tried to quote and double quote all over the place just to see if I could find something, but no luck.
Any idea on how to achieve that?