Hey guys I have a small script for making a parent folder with n number of subfolders.
I'm basing this off of the command mkdir -p parentFolder/{"Folder 1", "Folder 2",...}
.
Running this by writing it out like above will create the following folder structure:
parentFolder
|-Folder 1
|-Folder 2
|-Folder 3
#!/bin/bash
#Takes two arguments for the name of your parent folder
#and how many subfolders you want
function createFolderAndSubfolders {
folderName="$1"
numberOfSubfolders="$2"
subFolderName="subFolder"
buildString="$folderName/{"
for (( i=1; i<=$numberOfSubfolders; i++ ))
do
if [[ $i -ne $numberOfSubfolders ]]; then
buildString+="\"$subFolderName $i\","
else
# If last number in loop, don't add comma
buildString+="\"$subFolderName $i\""
fi
done
buildString+="}"
#This should make an example string like: 'parentFolder/{"subFolder 1","subFolder 2"}'
#Create parent and sub folders
mkdir -p "$buildString"
}
When I run it through with this string concatenation I'm getting the parent folder but only a single subfolder instead of what happens when typing it out manually.
parentFolder
|-{"subFolder 1","subFolder 2"}
I have also tried single quotes for escaping the double quotes to the same effect.
Am I missing anything that could prevent this from working?