I have written a simple bash script for backing up data,

Code:
#! /bin/sh

SRC=$1;
DEST=$2;

TODAY=$(date '+%y%m%d'); #get the date as a number in the form of ymd
TODAY_READABLE=$(date '+%m,%d,%y'); #get the date as the folder name will be m,d,y

LAST_BACKUP=$( ls $DEST | sed 's/^\(.*\),\(.*\),\(.*\)$/\3\1\2/g' | sort -nr | head -1); #get the last backup,
#as a number in the form of ymd

LAST_BACKUP_READABLE=$(echo $LAST_BACKUP | sed 's/^\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)$/\2,\3,\1/g'); #get the last
#backup as it is in the file name m,d,y

if [ "$(ls $DEST)" = "" ];
then 
	mkdir $DEST/$TODAY_READABLE
	rsync -r -H $SRC $DEST/$TODAY_READABLE;
else
	if [ "$LAST_BACKUP" = $TODAY ];
	then
		echo "backup already completed for today, overwrite? [yes/no]"
		read OVERWRITE;
		
		if [ "$OVERWRITE" = "yes" ];
		then
			rm -rf $DEST/$LAST_BACKUP_READABLE;
			mkdir $DEST/$LAST_BACKUP_READABLE;
			rsync -r -H --link-dest=../$LAST_BACKUP_READABLE $SRC $DEST/$LAST_BACKUP_READABLE;

		else #doesn't want to overwrite
			exit 1;
		fi

		exit 0;

	else #last backup was yesterday

		mkdir $DEST/$TODAY_READABLE;

		rsync -r -H --link-dest=../$LAST_BACKUP_READABLE     $SRC     $DEST/$TODAY_READABLE

	fi
fi
and no matter what I do, I can't get it to link files back to the files from the directory for the backup for the previous day, it keeps copying the files rather than linking them

I am using rsync version 3.0.7