On Fri, Dec 06, 2024 at 18:46:06 -0500, e...@gmx.us wrote:
> You could do something
> overengineered like defining an array "excludepatterns" for patterns, and
> then doing something like
> 
> rsync  \
> $(for pattern in ${excludepatterns[@]} ; do
>   echo -- "--exclude  '$pattern'"
> done)
> 
> Modulo mistakes, of course.

This definitely has mistakes.  You're expanding each of the patterns
based on the files in the current working directory.

hobbit:~$ exclusions=( '*.mp3' '*.mp4' '*.wav' )
hobbit:~$ echo *.mp3
christmas-peebs.mp3 inmexico.mp3 Kristie_and_John_-_Bobby_McGee.mp3
hobbit:~$ for p in ${exclusions[@]}; do echo -- "--exclude '$p'"; done
-- --exclude 'christmas-peebs.mp3'
-- --exclude 'inmexico.mp3'
-- --exclude 'Kristie_and_John_-_Bobby_McGee.mp3'
-- --exclude '*.mp4'
-- --exclude '*.wav'

That's not what you want.  (You're also writing a literal -- which is
not wanted.)

As I wrote in the previous message, you can generate the second array
using a single command that doesn't perform pathname expansions:

hobbit:~$ opts=( "${exclusions[@]/#/--exclude=}" )
hobbit:~$ declare -p opts
declare -a opts=([0]="--exclude=*.mp3" [1]="--exclude=*.mp4" 
[2]="--exclude=*.wav")

Reply via email to