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?
rsync, apsof the process look like/usr/bin/rsync --exclude=*.vim* --exclude=/home/user1 --exclude=/home/user2 . DESTINATIONand hidden file who aren't expended go through the filter. – Vlycop Doo Aug 01 '18 at 17:50for x in $(cat file), the words infilewill be used as globs right there, since the command substitution is unquoted. Another reason to usewhile readormapfile, then. I added an example. – ilkkachu Aug 01 '18 at 19:00set -f; IFS=$'\n'; for line in $(cat file); do ...; doneand you'd get to read the file line-by-line, but I'm not sure that's very nice either. – ilkkachu Aug 01 '18 at 19:03