I have created my first bash script today which basically creates a zip file of the directory in which the bash script sits. I can get the zip file to create just fine. But I am asking the user to specify which directories he wants to exclude from the zip (for example, on a wordpress website, the uploads folder can get very big so when creating the zip sometimes I would like to exclude that from the zip folder that gets created). I know that the following command works in this manner when run directly on the command line:-
zip -r new_public_html.zip . -x ./wp-content/uploads/**\*
However, my bash script asks the user to specify directories that he wants to exclude from the zip and I can see the value stored in the variable $THE_DIRECTORIES_TO_EXCLUDE
but for some reason when the zip file gets created it includes the uploads folder. I tried all of the statements which have been commented out in the bash script below - and none of them worked. As I say, I can get the zip file but I cannot exclude the folder the user specifies when asked. Any help would be greatly appreciated.
#!/bin/bash
read -p "Please specify the directories contained within wp-content that you would like to exclude. If you specify more than one directory, separate each exclusion by a space: " DIRECTORIES_TO_EXCLUDE
THE_DIRECTORIES_TO_EXCLUDE=""
for directory_to_exclude in $DIRECTORIES_TO_EXCLUDE
do
THE_DIRECTORIES_TO_EXCLUDE="$THE_DIRECTORIES_TO_EXCLUDE ./wp-content/$directory_to_exclude/**\*"
done
#zip -r new_public_html.zip . -x${THE_DIRECTORIES_TO_EXCLUDE}
#zip -r new_public_html.zip . -x"$THE_DIRECTORIES_TO_EXCLUDE"
#zip -r new_public_html.zip . -x ./wp-content/uploads/**\*
#zip -r new_public_html.zip . -x"${THE_DIRECTORIES_TO_EXCLUDE}"
#zip -r new_public_html.zip . -x eval "$THE_DIRECTORIES_TO_EXCLUDE"
#zip -r new_public_html.zip . -x eval $THE_DIRECTORIES_TO_EXCLUDE
#cmd='zip -r new_public_html.zip . -x "$THE_DIRECTORIES_TO_EXCLUDE"'
#eval "$cmd";
#newcmd=$(zip -r new_public_html.zip . -x$THE_DIRECTORIES_TO_EXCLUDE)
#echo newcmd;
echo "directories to exclude have been set to : $THE_DIRECTORIES_TO_EXCLUDE"