无法在 bash 脚本中从 rsync 中排除目录

Not being able to exclude directory from rsync in a bash script

我已经编写了一个 bash 脚本来备份我的项目目录,但排除选项不起作用。

backup.sh

#!/bin/sh
DRY_RUN=""
if [ ="-n" ]; then
    DRY_RUN="n"
fi

OPTIONS="-a"$DRY_RUN"v --delete --delete-excluded --exclude='/bin/'"
SOURCE="/home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system/"
DEST="/home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system_backup"

rsync $OPTIONS $SOURCE $DEST

当我在终端上单独执行命令时,它有效。

vikram:student_information_system$ rsync -anv --delete --delete-excluded --exclude='/bin/' /home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system/ /home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system_backup
sending incremental file list
deleting bin/student_information_system/model/StudentTest.class
deleting bin/student_information_system/model/Student.class
deleting bin/student_information_system/model/
deleting bin/student_information_system/
deleting bin/
./
.backup.sh.swp
backup.sh
backup.sh~

sent 507 bytes  received 228 bytes  1,470.00 bytes/sec
total size is 16,033  speedup is 21.81 (DRY RUN)
vikram:student_information_system$ 

要排除的目录名称周围的单引号导致了问题(在此 answer 中进行了解释)。
我还按照 here 的说明将所有选项存储在一个数组中。

删除单引号,将选项存储在数组中,按照@Cyrus 在评论中的建议对变量进行双引号,解决了问题。
我还必须将 #!/bin/sh 更改为 #!/bin/bash
更新的脚本:

#!/bin/bash
DRY_RUN=""
if [ "" = "-n" ]; then
    DRY_RUN="n"
fi

OPTS=( "-a""$DRY_RUN""v" "--delete" "--delete-excluded" "--exclude=/bin/" )
SRC="/home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system/"
DEST="/home/vikram/Documents/sem4/oop/lab/java_assignments/student_information_system_backup"

echo "rsync ${OPTS[@]} $SRC $DEST"
rsync "${OPTS[@]}" "$SRC" "$DEST"