I'm trying to make a bash script to lanch a tar command. I need the tar to have a variable parameter, but I can't have it work... Here it is:
i=1
for d in /home/test/*
do
dirs[i++]="${d%/}"
done
echo "There are ${#dirs[@]} dirs in the current path"
for((i=1;i<=${#dirs[@]};i++))
do
siteonly=${dirs[i]/\/home\/test\//}
if [[ $siteonly == "choubijoux" ]]
then
exclude='--exclude "aenlever/*"';
fi
tar -czf /backups/sites/$siteonly.tar.gz ${dirs[i]} --exclude "tmp/*" --exclude "temp/*" --exclude "cache/*" $exclude
done
The tar command execute, but without the parameter --exclude "aenlever/*" So I suppose the variable is not taken into consideration... Is there a way to make it accept the variable as parameter?