So, I'm writing a backup script, and wanted to skip .iso files.If I use the command from the command line, everything works fine:rsync -a --delete --exclude='*.iso' /home/user/Desktop/Work /mnt/profile/Desktop/But, when I try to use it inside my script, is doesn't get the EXCLUDE settings, and proceed to copy .iso files. This is the script:#!/bin/bashset -eSRC_DIR=/home/user/Desktop/WorkDST_MOUNTPOINT=/mnt/profileDST_DIR=/mnt/profile/Desktop/OPTIONS= --exclude='*.iso' mountpoint -q $DST_MOUNTPOINT || mount $DST_MOUNTPOINTrsync -a --delete $OPTIONS $SRC_DIR $DST_DIRIf I run the script, get its PID and check /proc/PID/cmdline, the EXCLUDE settings is there. What I'm doing wrong?
Rsync behave differently if invoked inside script
bash;shell script;scripting
You're putting quotes on the exclude pattern.OPTIONS= --exclude='*.iso' rsync $OPTIONSHere, OPTIONS contains <space>--exclude='*.iso'<space>. Since it's not quoted on the rsync command line, word-splitting happens, removing the spaces at the ends. But the single-quotes in the string remain, and are passed to rsync. The pattern doesn't match since you're not likely to have file names with quotes at the start and the end.Remove the extra quotes (and the spaces) and quote your variables:OPTIONS=--exclude=*.isorsync $OPTIONS $SRC_DIR $DST_DIR