I have the following bash array:
IGNORED_DIRS=(
"vendor"
"node_modules"
"bower_components"
"tmp"
"backup"
)
And I need this to be outputted in such a way:
tar -cpzf /var/backups/ --exclude="vendor" --exclude="node_modules" --exclude="bower_components" --exclude="tmp" --exclude="backup"
So far, I have tried the following:
for dir in ${IGNORED_DIRS[@]}
do
EXCLUDES=$EXCLUDES" --exclude=\""$dir"\""
done
So that I would end up with a variable containing the exact exclude string. I thought I could simply do
tar -cpzf /var/backups/ $EXCLUDES
But that simply ignores all of the exclude flags. Has anyone got the solution for me?
EXCLUDESline with thisEXCLUDES=$EXCLUDES" --exclude="$dir" "seems to fix the issue. So now there are no quotes surrounding the exclude directories anymore. Strange that his does work...