Sample Header Ad - 728x90

Why do these rsync filter args fail in bash when passed in array?

0 votes
2 answers
610 views
Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}" -av --prune-empty-dirs -f "- *.flac" -f "- *.WMA" -f "- *.wma" -f "- *.ogg" -f "- *.mp4" -f "- *.m4a" -f "- *.webm" -f "- *.wav" -f "- *.ape" -f "- *.zip" -f "- *.rar" $ echo ${options} -f $ echo ${options} "- *.wma" Then the source directory, from which rsync is to copy files: $ echo "\"$dir/\"" "/media/test/Ahmad Jamal Trio/Live at the Pershing/" And the target directory, to which rsync is to copy files: $ echo "\"$target_dir\"" "/home/test/mp3/Ahmad Jamal Trio/Live at the Pershing/" Put it all together: $ echo "${options[@]}" "\"$dir/\"" "\"$target_dir\"" -av --prune-empty-dirs -f "- *.flac" -f "- *.WMA" -f "- *.wma" -f "- *.ogg" -f "- *.mp4" -f "- *.m4a" -f "- *.webm" -f "- *.wav" -f "- *.ape" -f "- *.zip" -f "- *.rar" "/media/test/Ahmad Jamal Trio/Live at the Pershing//" "/home/test/mp3/Ahmad Jamal Trio/Live at the Pershing/" That all looks like it should. And indeed, it does work if you give the command literally, like this: $ rsync -av --prune-empty-dirs -f "- *.flac" -f "- *.WMA" -f "- *.wma" -f "- *.ogg" -f "- *.mp4" -f "- *.m4a" -f "- *.webm" -f "- *.wav" -f "- *.ape" -f "- *.zip" -f "- *.rar" "/media/test/Ahmad Jamal Trio/Live at the Pershing/" "/home/test/mp3/Ahmad Jamal Trio/Live at the Pershing/" ./ Ahmad Jamal Trio - Live at the Pershing - 01 - But Not for Me.mp3 Ahmad Jamal Trio - Live at the Pershing - 02 - Surrey With The Fringe On Top.mp3 Ahmad Jamal Trio - Live at the Pershing - 03 - Moonlight In Vermont.mp3 Ahmad Jamal Trio - Live at the Pershing - 04 - Music, Music, Music.mp3 Ahmad Jamal Trio - Live at the Pershing - 05 - No Greater Love.mp3 Ahmad Jamal Trio - Live at the Pershing - 06 - Poinciana.mp3 Ahmad Jamal Trio - Live at the Pershing - 07 - Wood'yn You.mp3 Ahmad Jamal Trio - Live at the Pershing - 08 - What's New.mp3 AlbumArtSmall.jpg AlbumArtLarge.jpg Folder.jpg sent 43,194,376 bytes received 285 bytes 28,796,440.67 bytes/sec total size is 43,182,454 speedup is 1.00 But it fails when I call rsync using the vars as args: $ rsync "${options[@]}" "\"$dir/\"" "\"$target_dir\"" Unknown filter rule: `"- *.flac"' rsync error: syntax or usage error (code 1) at exclude.c(902) [client=3.1.2]
Asked by markling (231 rep)
Nov 5, 2019, 10:40 AM
Last activity: Dec 29, 2024, 11:04 AM